diff --git a/api/ovdashboard_api/main.py b/api/ovdashboard_api/main.py index 74881b8..477ae0b 100644 --- a/api/ovdashboard_api/main.py +++ b/api/ovdashboard_api/main.py @@ -7,6 +7,8 @@ Creates the main `FastAPI` app. """ from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware +from fastapi.staticfiles import StaticFiles from uvicorn import run as uvicorn_run from .dav_common import webdav_check @@ -37,6 +39,30 @@ 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",