40 lines
852 B
Python
40 lines
852 B
Python
import logging
|
|
from contextlib import asynccontextmanager
|
|
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.responses import ORJSONResponse
|
|
from starlette.staticfiles import StaticFiles
|
|
|
|
from core.config import STATIC_DIR, settings
|
|
from core.models.db_helper import db_helper
|
|
|
|
from api import router as swagger_router
|
|
|
|
log = logging.getLogger()
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
yield
|
|
await db_helper.dispose()
|
|
|
|
|
|
main_app = FastAPI(
|
|
default_response_class=ORJSONResponse,
|
|
lifespan=lifespan,
|
|
docs_url=None,
|
|
)
|
|
|
|
main_app.include_router(swagger_router)
|
|
|
|
main_app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run(
|
|
"main:main_app",
|
|
host=settings.run.host,
|
|
port=settings.run.port,
|
|
reload=settings.run.reload,
|
|
)
|