Initial commit: Robot ökoszisztéma v2.0 - Stabilizált jármű és szerviz robotok
This commit is contained in:
54
code-server-config/data/User/History/-5314da0c/FkfR.py
Executable file
54
code-server-config/data/User/History/-5314da0c/FkfR.py
Executable file
@@ -0,0 +1,54 @@
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.database import engine, Base
|
||||
from app.api.v1.router import api_router
|
||||
|
||||
# --- Lifespan Manager (Startup & Shutdown Logic) ---
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# STARTUP: Adatbázis táblák létrehozása
|
||||
# Figyelem: Éles környezetben (Production) inkább Alembic migrációt használunk!
|
||||
async with engine.begin() as conn:
|
||||
# Betöltjük a modelleket, hogy a metadata tudjon róluk
|
||||
# Fontos: importálni kell őket, különben nem jönnek létre!
|
||||
from app.models import social, vehicle, user, logistics
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
print("--- Database Tables Checked/Created ---")
|
||||
|
||||
yield # Itt fut az alkalmazás...
|
||||
|
||||
# SHUTDOWN: Erőforrások felszabadítása (ha lenne)
|
||||
print("--- Shutting down ---")
|
||||
|
||||
# --- App Initialization ---
|
||||
app = FastAPI(
|
||||
title=settings.PROJECT_NAME,
|
||||
version=settings.VERSION,
|
||||
openapi_url=f"{settings.API_V1_STR}/openapi.json",
|
||||
lifespan=lifespan
|
||||
)
|
||||
|
||||
# --- Middleware (CORS) ---
|
||||
# Engedélyezzük a frontend kommunikációt
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"], # Élesben szigorítani kell!
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# --- Routers ---
|
||||
app.include_router(api_router, prefix=settings.API_V1_STR)
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {
|
||||
"message": "Traffic Ecosystem SuperApp API is Running",
|
||||
"docs_url": "/docs",
|
||||
"version": settings.VERSION
|
||||
}
|
||||
Reference in New Issue
Block a user