30 lines
684 B
Python
30 lines
684 B
Python
import os
|
|
from fastapi import FastAPI
|
|
from contextlib import asynccontextmanager
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.config import settings
|
|
from app.database import engine, init_db
|
|
from app.routers import sessions, stats
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
await init_db()
|
|
yield
|
|
|
|
|
|
app = FastAPI(lifespan=lifespan, root_path=os.getenv("ROOT_PATH", ""))
|
|
|
|
# CORS middleware
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.CORS_ORIGINS.split(","),
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(sessions.router)
|
|
app.include_router(stats.router)
|