from contextlib import asynccontextmanager from starlette.staticfiles import StaticFiles from settings import settings from models import db_helper from api import router as api_router from views import router as web_router import uvicorn from fastapi import FastAPI from fastapi.responses import ORJSONResponse @asynccontextmanager async def lifespan(app: FastAPI): yield await db_helper.dispose() main_app = FastAPI( default_response_class=ORJSONResponse, lifespan=lifespan, ) main_app.include_router(api_router) main_app.include_router(web_router) main_app.mount("/static", StaticFiles(directory="views/static"), name="static") if __name__ == "__main__": uvicorn.run( "main:main_app", host=settings.run.host, port=settings.run.port, reload=settings.run.reload, )