import logging from contextlib import asynccontextmanager import uvicorn from fastapi import FastAPI from fastapi.openapi.docs import get_swagger_ui_html from fastapi.responses import ORJSONResponse from starlette.staticfiles import StaticFiles from core.config import BASE_DIR, settings log = logging.getLogger() @asynccontextmanager async def lifespan(app: FastAPI): try: yield finally: pass main_app = FastAPI( default_response_class=ORJSONResponse, lifespan=lifespan, docs_url=None, ) main_app.mount("/static", StaticFiles(directory=BASE_DIR / "static"), name="static") @main_app.get("/docs", include_in_schema=False) async def custom_swagger_ui_html(): print(main_app.openapi_url) return get_swagger_ui_html( openapi_url=main_app.openapi_url, title="Blocked IP API", oauth2_redirect_url=main_app.swagger_ui_oauth2_redirect_url, swagger_js_url="/static/swagger/swagger-ui-bundle.js", swagger_css_url="/static/swagger/swagger-ui.css", swagger_favicon_url="/static/swagger/favicon.png", ) if __name__ == "__main__": uvicorn.run( "main:main_app", host=settings.run.host, port=settings.run.port, reload=settings.run.reload, )