Team Ai
Apppublic

ruby2210/todo-manager

sourceHugging Facemitupdated 9mo agoView on Hugging Face
0likes
main.py62 linesDownload Raw Back to src
1from fastapi import FastAPI2from src.core.config import settings3from src.core.rate_limiter import add_rate_limiting4from src.core.logging_config import setup_logging5from fastapi.middleware.cors import CORSMiddleware6 7 8# Set up logging9setup_logging()10 11app = FastAPI(12    title=settings.PROJECT_NAME,13    version=settings.VERSION,14    openapi_url=f"{settings.API_V1_STR}/openapi.json",15)16 17# Set up CORS18app.add_middleware(19    CORSMiddleware,20    allow_origins=[21        "*"22    ],  # For development, allow all. In production, specify frontend URL.23    allow_credentials=True,24    allow_methods=["*"],25    allow_headers=["*"],26)27 28# Add rate limiting29add_rate_limiting(app)30 31 32@app.on_event("startup")33async def on_startup():34    from src.database.config import create_db_and_tables35 36    await create_db_and_tables()37 38 39# Import and include API routers (deferred to avoid circular imports)40try:41    from src.api.v1.router import api_router42 43    app.include_router(api_router, prefix=settings.API_V1_STR)44except Exception as e:45    print(f"Warning: Could not load API routes: {e}")46 47 48@app.get("/health")49async def health_check():50    return {"status": "healthy", "timestamp": "2026-01-15T10:00:00Z"}51 52 53@app.get("/")54async def root():55    return {"message": "Todo Backend API is running!", "status": "success"}56 57 58if __name__ == "__main__":59    import uvicorn60 61    uvicorn.run(app, host="0.0.0.0", port=8000)62