46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api.admin_catalog import router as admin_catalog_router
|
|
from app.api.auth import router as auth_router
|
|
from app.api.internal_catalog import router as internal_catalog_router
|
|
from app.api.internal import router as internal_router
|
|
from app.api.me import router as me_router
|
|
from app.core.config import get_settings
|
|
from app.services.runtime_cache import runtime_cache
|
|
|
|
app = FastAPI(title="memberapi.ose.tw", version="0.1.0")
|
|
|
|
settings = get_settings()
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.public_frontend_origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.middleware("http")
|
|
async def invalidate_runtime_cache_on_cud(request, call_next):
|
|
response = await call_next(request)
|
|
if (
|
|
request.method in {"POST", "PUT", "PATCH", "DELETE"}
|
|
and request.url.path.startswith(("/admin", "/internal"))
|
|
and response.status_code < 400
|
|
):
|
|
runtime_cache.bump_revision()
|
|
return response
|
|
|
|
|
|
@app.get("/healthz", tags=["health"])
|
|
def healthz() -> dict[str, str]:
|
|
return {"status": "ok"}
|
|
|
|
|
|
app.include_router(internal_router)
|
|
app.include_router(internal_catalog_router)
|
|
app.include_router(admin_catalog_router)
|
|
app.include_router(me_router)
|
|
app.include_router(auth_router)
|