from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from contextlib import asynccontextmanager from app.core.config import settings from app.core.database import init_db, close_db from app.api.v1.router import api_router import logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) @asynccontextmanager async def lifespan(app: FastAPI): await init_db() logger.info("Database initialized") yield await close_db() logger.info("Database connection closed") app = FastAPI( title=settings.PROJECT_NAME, version=settings.VERSION, lifespan=lifespan ) app.add_middleware( CORSMiddleware, allow_origins=settings.BACKEND_CORS_ORIGINS, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router(api_router, prefix=settings.API_V1_STR) @app.get("/health") async def health_check(): return {"status": "healthy", "service": "OAuth Authentication System"}