CORS and StaticFiles settings
This commit is contained in:
parent
0cdf49cf3e
commit
1348869774
1 changed files with 26 additions and 0 deletions
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue