from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.api import todos, health from app.database.database import create_tables app = FastAPI( title="Todo App API", description="A simple Todo app API built with FastAPI", version="0.1.0", ) # Add CORS middleware app.add_middleware( CORSMiddleware, allow_origins=["*"], # For production, restrict this to specific domains allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Create database tables when app starts @app.on_event("startup") async def startup_event(): create_tables() # Include routers app.include_router(todos.router, prefix="/api/v1", tags=["todos"]) app.include_router(health.router, tags=["health"]) if __name__ == "__main__": import uvicorn uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)