advent22/api/advent22_api/app.py

47 lines
1.1 KiB
Python
Raw Permalink Normal View History

2022-10-08 23:36:16 +00:00
from fastapi import FastAPI
2022-10-27 23:48:02 +00:00
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
2022-10-08 23:36:16 +00:00
2023-09-08 18:17:18 +00:00
from .core.settings import SETTINGS
2022-10-09 00:18:15 +00:00
from .routers import router
2022-10-08 23:36:16 +00:00
app = FastAPI(
title="Advent22 API",
description="This API enables the `Advent22` service.",
contact={
"name": "Jörn-Michael Miehe",
"email": "jmm@yavook.de",
},
license_info={
"name": "MIT License",
"url": "https://opensource.org/licenses/mit-license.php",
},
openapi_url=SETTINGS.openapi_url,
docs_url=SETTINGS.docs_url,
redoc_url=SETTINGS.redoc_url,
)
2022-10-09 00:18:15 +00:00
2023-09-03 15:55:49 +00:00
app.include_router(router)
2022-10-27 23:48:02 +00:00
2023-09-03 15:55:49 +00:00
if SETTINGS.production_mode:
# Mount frontend in production mode
app.mount(
path="/",
app=StaticFiles(
directory=SETTINGS.ui_directory,
html=True,
),
name="frontend",
)
2022-10-27 23:48:02 +00:00
2023-09-03 15:55:49 +00:00
else:
# Allow CORS in debug mode
app.add_middleware(
CORSMiddleware,
allow_credentials=True,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
expose_headers=["*"],
)