From cc90a1edf7a7937d0ab1df78bcdc881e02ee4b34 Mon Sep 17 00:00:00 2001 From: Ayush Sehrawat <69469790+AyushSehrawat@users.noreply.github.com> Date: Sun, 16 Jun 2024 14:43:22 +0530 Subject: [PATCH] chore: minor fastapi tweaks (#414) --- backend/main.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/backend/main.py b/backend/main.py index 2ef32d51..19d6856d 100644 --- a/backend/main.py +++ b/backend/main.py @@ -30,10 +30,12 @@ async def dispatch(self, request: Request, call_next): finally: process_time = time.time() - start_time logger.log( - "API", f"{request.method} {request.url.path} - {response.status_code if 'response' in locals() else '500'} - {process_time:.2f}s" + "API", + f"{request.method} {request.url.path} - {response.status_code if 'response' in locals() else '500'} - {process_time:.2f}s", ) return response + parser = argparse.ArgumentParser() parser.add_argument( "--ignore_cache", @@ -43,7 +45,16 @@ async def dispatch(self, request: Request, call_next): args = parser.parse_args() -app = FastAPI() +app = FastAPI( + title="Riven", + summary="A media management system.", + version="0.7.x", + redoc_url=None, + license_info={ + "name": "GPL-3.0", + "url": "https://www.gnu.org/licenses/gpl-3.0.en.html", + }, +) app.program = Program(args) app.add_middleware(LoguruMiddleware) @@ -61,6 +72,7 @@ async def dispatch(self, request: Request, call_next): app.include_router(webhooks_router) app.include_router(tmdb_router) + class Server(uvicorn.Server): def install_signal_handlers(self): pass @@ -80,6 +92,7 @@ def run_in_thread(self): finally: self.should_exit = True + config = uvicorn.Config(app, host="0.0.0.0", port=8080, log_config=None) server = Server(config=config) @@ -96,4 +109,4 @@ def run_in_thread(self): finally: app.program.stop() logger.critical("Server has been stopped") - sys.exit(0) \ No newline at end of file + sys.exit(0)