netadm/main.py

37 lines
809 B
Python
Raw Normal View History

2024-10-20 09:44:26 +00:00
import logging as log
from config import conf, STATIC_DIR
2024-10-01 11:29:39 +00:00
import uvicorn
2024-10-01 11:37:29 +00:00
from fastapi import FastAPI
from fastapi.responses import ORJSONResponse
2024-10-01 12:05:49 +00:00
from starlette.staticfiles import StaticFiles
2024-10-20 09:44:26 +00:00
from routers import router
from contextlib import asynccontextmanager
2024-10-01 20:06:21 +00:00
@asynccontextmanager
async def lifespan(app: FastAPI):
yield
2024-10-20 09:44:26 +00:00
log.info("main APP stopped")
2024-10-01 20:06:21 +00:00
2024-10-01 11:37:29 +00:00
main_app = FastAPI(
default_response_class=ORJSONResponse,
docs_url=None,
2024-10-20 09:44:26 +00:00
lifespan=lifespan,
2024-10-01 11:37:29 +00:00
)
2024-10-01 14:09:19 +00:00
2024-10-20 09:44:26 +00:00
main_app.include_router(router)
2024-10-01 12:05:49 +00:00
2024-10-20 09:44:26 +00:00
main_app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
2024-10-01 11:37:29 +00:00
2024-10-01 11:29:39 +00:00
if __name__ == "__main__":
2024-10-20 09:44:26 +00:00
log.info("Starting server")
2024-10-01 11:29:39 +00:00
uvicorn.run(
"main:main_app",
2024-10-20 09:44:26 +00:00
host=conf.run.host,
port=conf.run.port,
reload=conf.run.reload,
2024-10-01 11:29:39 +00:00
)
2024-10-20 09:44:26 +00:00
log.info("Server stopped")