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: app = FastAPI() from cbh.api.message import message_router app.include_router(message_router, tags=['message']) from cbh.api.chat import chat_router app.include_router(chat_router, tags=['chat']) app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"], ) @app.exception_handler(StarletteHTTPException) async def http_exception_handler(_, exc): return CbhResponseWrapper( data=None, successful=False, error=ErrorCbhResponse(message=str(exc.detail)) ).response(exc.status_code) @app.get("/") async def read_root(): return {"report": "Hello world!"} return app