Spaces:
Sleeping
Sleeping
| import os | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from starlette.exceptions import HTTPException as StarletteHTTPException | |
| from starlette.staticfiles import StaticFiles | |
| from trauma.core.config import settings | |
| from trauma.core.wrappers import TraumaResponseWrapper, ErrorTraumaResponse | |
| def create_app() -> FastAPI: | |
| app = FastAPI() | |
| from trauma.api.account import account_router | |
| app.include_router(account_router, tags=["account"]) | |
| from trauma.api.chat import chat_router | |
| app.include_router(chat_router, tags=['chat']) | |
| from trauma.api.message import message_router | |
| app.include_router(message_router, tags=['message']) | |
| from trauma.api.security import security_router | |
| app.include_router(security_router, tags=['security']) | |
| from trauma.api.data import facility_router | |
| app.include_router(facility_router, tags=['facility']) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| static_directory = os.path.join(settings.BASE_DIR, 'static') | |
| if not os.path.exists(static_directory): | |
| os.makedirs(static_directory) | |
| app.mount( | |
| '/static', | |
| StaticFiles(directory='static'), | |
| ) | |
| async def http_exception_handler(_, exc): | |
| return TraumaResponseWrapper( | |
| data=None, | |
| successful=False, | |
| error=ErrorTraumaResponse(message=str(exc.detail)) | |
| ).response(exc.status_code) | |
| async def read_root(): | |
| return {"message": "Hello world!"} | |
| return app | |