netadm/main.py

37 lines
809 B
Python

import logging as log
from config import conf, STATIC_DIR
import uvicorn
from fastapi import FastAPI
from fastapi.responses import ORJSONResponse
from starlette.staticfiles import StaticFiles
from routers import router
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
yield
log.info("main APP stopped")
main_app = FastAPI(
default_response_class=ORJSONResponse,
docs_url=None,
lifespan=lifespan,
)
main_app.include_router(router)
main_app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
if __name__ == "__main__":
log.info("Starting server")
uvicorn.run(
"main:main_app",
host=conf.run.host,
port=conf.run.port,
reload=conf.run.reload,
)
log.info("Server stopped")