import uvicorn from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.openapi.utils import get_openapi from app.api.v1.api import api_router from app.db.base import Base from app.db.session import engine # Create tables if they don't exist Base.metadata.create_all(bind=engine) app = FastAPI( title="Task Management API", description="A simple REST API for managing tasks", version="0.1.0", ) # Configure CORS app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include API router app.include_router(api_router, prefix="/api/v1") @app.get("/", tags=["root"]) async def root(): """ Root endpoint returning API information. """ return { "title": "Task Management API", "docs_url": "/docs", "openapi_url": "/openapi.json", "health_check": "/api/v1/health", } @app.get("/openapi.json", include_in_schema=False) async def get_open_api_endpoint(): """ Expose OpenAPI schema. """ return get_openapi( title="Task Management API", version="0.1.0", description="A simple REST API for managing tasks", routes=app.routes, ) if __name__ == "__main__": uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)