from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.auth.router import router as auth_router from app.config import settings from app.db.base import Base from app.db.session import engine # Import models so Base.metadata knows about them import app.db.models # noqa: F401 @asynccontextmanager async def lifespan(app: FastAPI): async with engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) yield app = FastAPI(lifespan=lifespan) app.add_middleware( CORSMiddleware, allow_origins=settings.CORS_ORIGINS.split(","), allow_methods=["*"], allow_headers=["*"], allow_credentials=True, ) app.include_router(auth_router, prefix="/api/auth") @app.get("/api/health") async def health(): return {"status": "ok"}