osnova-api-alert/main.py

37 lines
809 B
Python
Raw Permalink Normal View History

2024-10-08 11:26:04 +00:00
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
2024-10-08 16:10:34 +00:00
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
yield
2024-10-09 08:28:57 +00:00
log.info("main APP stopped")
2024-10-08 16:10:34 +00:00
2024-10-08 11:26:04 +00:00
main_app = FastAPI(
default_response_class=ORJSONResponse,
docs_url=None,
2024-10-08 16:10:34 +00:00
lifespan=lifespan,
2024-10-08 11:26:04 +00:00
)
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")