Spaces:
Sleeping
Sleeping
| # pylint: disable=C0415 | |
| """ | |
| ClipboardHealthAI application package. | |
| """ | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from starlette.exceptions import HTTPException as StarletteHTTPException | |
| from cbh.core.wrappers import CbhResponseWrapper, ErrorCbhResponse | |
| def create_app() -> FastAPI: | |
| """ | |
| Create and configure the FastAPI application. | |
| """ | |
| app = FastAPI() | |
| from cbh.api.coach import coach_router | |
| app.include_router(coach_router, tags=["coach"]) | |
| from cbh.core.config import settings | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| async def http_exception_handler(_, exc): | |
| """ | |
| Handle HTTP exceptions and convert them to standardized error responses. | |
| """ | |
| return CbhResponseWrapper( | |
| data=None, successful=False, error=ErrorCbhResponse(message=str(exc.detail)) | |
| ).response(exc.status_code) | |
| async def startup_event(): | |
| """ | |
| Execute startup tasks when the application starts. | |
| """ | |
| async def health(): | |
| """ | |
| Health check endpoint for container orchestration and monitoring. | |
| """ | |
| return {"status": "healthy one"} | |
| async def root(): | |
| """ | |
| Root endpoint for the application. | |
| """ | |
| return {"message": "Hello, World!"} | |
| return app | |