atlantis-realtime / cbh /__init__.py
brestok's picture
init
eda70df
# 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=["*"],
)
@app.exception_handler(StarletteHTTPException)
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)
@app.on_event("startup")
async def startup_event():
"""
Execute startup tasks when the application starts.
"""
@app.get("/api/health")
async def health():
"""
Health check endpoint for container orchestration and monitoring.
"""
return {"status": "healthy one"}
@app.get("/")
async def root():
"""
Root endpoint for the application.
"""
return {"message": "Hello, World!"}
return app