Spaces:
Sleeping
Sleeping
File size: 988 Bytes
516495b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from starlette.exceptions import HTTPException as StarletteHTTPException
from idreamers.core.config import settings
from idreamers.core.wrappers import PilotResponseWrapper, ErrorPilotResponse
def create_app() -> FastAPI:
app = FastAPI()
from idreamers.api.calculation import calculation_router
app.include_router(calculation_router, tags=['calculation'])
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
@app.exception_handler(StarletteHTTPException)
async def http_exception_handler(_, exc):
return PilotResponseWrapper(
data=None,
successful=False,
error=ErrorPilotResponse(message=str(exc.detail))
).response(exc.status_code)
@app.get("/")
async def read_root():
return {"calculation": "Hello world!"}
return app
|