Last commit not found
from fastapi import FastAPI, Request | |
from starlette.middleware.cors import CORSMiddleware | |
from fastapi.responses import JSONResponse | |
from api.logger import setup_logger | |
from api.routes import router | |
logger = setup_logger(__name__) | |
def create_app(): | |
app = FastAPI( | |
title="NiansuhAI API Gateway", | |
docs_url=None, # Disable Swagger UI | |
redoc_url=None, # Disable ReDoc | |
openapi_url=None, # Disable OpenAPI schema | |
) | |
# CORS settings | |
app.add_middleware( | |
CORSMiddleware, | |
allow_origins=["*"], # Adjust as needed for security | |
allow_credentials=True, | |
allow_methods=["*"], | |
allow_headers=["*"], | |
) | |
# Include routes | |
app.include_router(router) | |
# Global exception handler for better error reporting | |
async def global_exception_handler(request: Request, exc: Exception): | |
logger.error(f"An error occurred: {str(exc)}") | |
return JSONResponse( | |
status_code=500, | |
content={"message": "An internal server error occurred."}, | |
) | |
return app | |
app = create_app() | |