import uvicorn from fastapi import FastAPI, HTTPException, status from fastapi.exceptions import RequestValidationError from fastapi.middleware.cors import CORSMiddleware from pydantic import ValidationError from app.api.api import api_router from app.api.errors import ( APIError, api_error_handler, http_error_handler, validation_error_handler, ) # Create all tables in the database # Comment this out if you're using Alembic migrations # Base.metadata.create_all(bind=engine) app = FastAPI( title="Todo API", description="A simple REST API for managing todo items", version="0.1.0", ) # Add exception handlers app.add_exception_handler(HTTPException, http_error_handler) app.add_exception_handler(APIError, api_error_handler) app.add_exception_handler(RequestValidationError, validation_error_handler) app.add_exception_handler(ValidationError, validation_error_handler) # Enable CORS app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include the API router app.include_router(api_router) @app.get("/health", status_code=status.HTTP_200_OK) async def health_check(): return {"status": "healthy"} if __name__ == "__main__": uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)