Spaces:
Runtime error
Runtime error
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from contextlib import asynccontextmanager | |
| from core.config import settings | |
| from database.connection import db_client | |
| from api.v1 import documents | |
| async def lifespan(app: FastAPI): | |
| # Connect to MongoDB at startup | |
| db_client.connect() | |
| yield | |
| # Disconnect from MongoDB at shutdown | |
| db_client.disconnect() | |
| app = FastAPI( | |
| title=settings.PROJECT_NAME, | |
| openapi_url=f"{settings.API_V1_STR}/openapi.json", | |
| lifespan=lifespan | |
| ) | |
| # Connect the backend to the TanStack Start frontend (allowing CORS) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=settings.BACKEND_CORS_ORIGINS, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Include Routers | |
| app.include_router( | |
| documents.router, | |
| prefix=settings.API_V1_STR, | |
| tags=["Documents"] | |
| ) | |
| async def health_check(): | |
| return {"status": "healthy", "service": settings.PROJECT_NAME} |