From 77b40848b889baa41e4b5bd31f0c12ed3adcf038 Mon Sep 17 00:00:00 2001 From: LaoWang <257199637@qq.com> Date: Tue, 9 Jun 2026 16:03:34 +0000 Subject: [PATCH] fix: add no-cache middleware to prevent OpenResty proxy caching HTML/JS/CSS --- api/server.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/api/server.py b/api/server.py index 547bbb1..ab3a5d1 100644 --- a/api/server.py +++ b/api/server.py @@ -584,6 +584,18 @@ def health(): # ─── Mount static frontend (at /) ────────────────────── # Static files mounted after API routes to avoid conflicts static_dir = ROOT / "static" + +@app.middleware("http") +async def add_no_cache_headers(request: Request, call_next): + """Add no-cache headers to HTML/JS/CSS to prevent OpenResty proxy caching.""" + response = await call_next(request) + path = request.url.path + if path == "/" or any(path.endswith(ext) for ext in (".html", ".js", ".css")): + response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" + response.headers["Pragma"] = "no-cache" + response.headers["Expires"] = "0" + return response + if static_dir.exists() and any(static_dir.iterdir()): app.mount("/", StaticFiles(directory=str(static_dir), html=True), name="static")