from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.api.api_v1.api import api_router from app.core.config import settings from app.core.error_handlers import add_exception_handlers app = FastAPI( title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json", version="0.1.0", description="A simple task management API with FastAPI and SQLite.", docs_url="/docs", redoc_url="/redoc", ) # Set all CORS enabled origins if settings.BACKEND_CORS_ORIGINS: app.add_middleware( CORSMiddleware, allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Add exception handlers add_exception_handlers(app) # Include API router app.include_router(api_router, prefix=settings.API_V1_STR) # Root endpoint redirects to docs @app.get("/", include_in_schema=False) async def root(): """Root endpoint redirects to docs.""" from fastapi.responses import RedirectResponse return RedirectResponse(url="/docs") if __name__ == "__main__": import uvicorn uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)