import logging from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse from app.config import get_settings from app.routers import health logger = logging.getLogger("app") def create_app() -> FastAPI: settings = get_settings() app = FastAPI(title=settings.app_name) if settings.cors_origins: app.add_middleware( CORSMiddleware, allow_origins=settings.cors_origins, allow_methods=["*"], allow_headers=["*"], ) @app.exception_handler(Exception) async def unhandled(request: Request, exc: Exception) -> JSONResponse: logger.exception("Unhandled error on %s %s", request.method, request.url.path) return JSONResponse(status_code=500, content={"detail": "Internal server error"}) app.include_router(health.router) # Include feature routers here, e.g. app.include_router(items.router, prefix="/items") return app app = create_app()