Spaces:
No application file
No application file
| """ | |
| FastAPI application entry point. | |
| Configures middleware, CORS, and routes. | |
| """ | |
| 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 create_db_tables | |
| from app.middleware.jwt_middleware import verify_jwt_token | |
| from app.api.routes import auth, todos | |
| async def lifespan(app: FastAPI): | |
| """Create database tables on startup.""" | |
| create_db_tables() | |
| yield | |
| # Create FastAPI application | |
| app = FastAPI( | |
| title=settings.APP_NAME, | |
| debug=settings.DEBUG, | |
| version="1.0.0", | |
| lifespan=lifespan, | |
| ) | |
| # Configure CORS | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=settings.CORS_ORIGINS, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Register JWT verification middleware | |
| app.middleware("http")(verify_jwt_token) | |
| # Health check endpoint | |
| async def health_check(): | |
| """Health check endpoint.""" | |
| return {"status": "healthy"} | |
| # Include routers | |
| app.include_router(auth.router, prefix="/api") | |
| app.include_router(todos.router, prefix="/api") | |