From 1d8748e63adb98f760af46fd6ac085d8bf3ed5d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 15 Sep 2022 22:41:23 +0000 Subject: [PATCH] add middlewares (uvicorn) --- api/ovdashboard_api/main.py | 48 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/api/ovdashboard_api/main.py b/api/ovdashboard_api/main.py index 477ae0b..14bbf17 100644 --- a/api/ovdashboard_api/main.py +++ b/api/ovdashboard_api/main.py @@ -33,36 +33,36 @@ app = FastAPI( app.include_router(main_router) +if SETTINGS.production_mode: + # Mount frontend in production mode + app.mount( + path="/", + app=StaticFiles( + directory="/html", + html=True, + ), + name="frontend", + ) + +else: + # Allow CORS in debug mode + app.add_middleware( + CORSMiddleware, + allow_origins=[ + "*", + ], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], + expose_headers=["*"], + ) + def main() -> None: """ If the `main` script is run, `uvicorn` is used to run the app. """ - if SETTINGS.production_mode: - # Mount frontend in production mode - app.mount( - path="/", - app=StaticFiles( - directory="/html", - html=True, - ), - name="frontend", - ) - - else: - # Allow CORS in debug mode - app.add_middleware( - CORSMiddleware, - allow_origins=[ - "*", - ], - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], - expose_headers=["*"], - ) - if webdav_check(): uvicorn_run( app="ovdashboard_api.main:app",