mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 00:03:07 +00:00
app middlewares
This commit is contained in:
parent
cf812f23cd
commit
4567ab12f8
2 changed files with 31 additions and 0 deletions
|
@ -1,4 +1,6 @@
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
from .routers import router
|
from .routers import router
|
||||||
from .settings import SETTINGS
|
from .settings import SETTINGS
|
||||||
|
@ -19,4 +21,32 @@ app = FastAPI(
|
||||||
redoc_url=SETTINGS.redoc_url,
|
redoc_url=SETTINGS.redoc_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.on_event("startup")
|
||||||
|
async def add_middlewares() -> None:
|
||||||
|
if SETTINGS.production_mode:
|
||||||
|
# Mount frontend in production mode
|
||||||
|
app.mount(
|
||||||
|
path="/",
|
||||||
|
app=StaticFiles(
|
||||||
|
directory=SETTINGS.ui_directory,
|
||||||
|
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=["*"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
app.include_router(router)
|
app.include_router(router)
|
||||||
|
|
|
@ -35,6 +35,7 @@ class Settings(BaseSettings):
|
||||||
#####
|
#####
|
||||||
|
|
||||||
production_mode: bool = False
|
production_mode: bool = False
|
||||||
|
ui_directory: str = "/html"
|
||||||
|
|
||||||
#####
|
#####
|
||||||
# openapi settings
|
# openapi settings
|
||||||
|
|
Loading…
Reference in a new issue