spark / cbh /__init__.py
brestok's picture
fix
c40ddce
# pylint: disable=C0415
"""
ClipboardHealthAI application package.
"""
import asyncio
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(docs_url="/api/docs", openapi_url="/api/openapi.json")
from cbh.api.account import account_router
app.include_router(account_router, tags=["account"])
from cbh.api.availability import availability_router
app.include_router(availability_router, tags=["availability"])
from cbh.api.calls import calls_router
app.include_router(calls_router, tags=["calls"])
# from cbh.api.discountcode import discountcode_router
# app.include_router(discountcode_router, tags=["discountcodes"])
from cbh.api.events import events_router
app.include_router(events_router, tags=["events"])
from cbh.api.security import security_router
app.include_router(security_router, tags=["security"])
app.add_middleware(
CORSMiddleware,
allow_origin_regex=".*",
allow_credentials=True,
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"}
@app.get("/")
async def root():
"""
Root endpoint for the application.
"""
return {"message": "hi!"}
return app