Fix: Cache-Busting fuer JS/CSS (?v=Inhalts-Hash) + Cache-Control: no-cache — alte gecachte app.js ohne Such-Polling verhinderte Live-Ergebnisse
This commit is contained in:
+16
-1
@@ -1,4 +1,5 @@
|
||||
"""CIS Enhanced - FastAPI app."""
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import threading
|
||||
@@ -33,7 +34,8 @@ client = CISClient(os.environ["CIS_USER"], os.environ["CIS_PASSWORD"], BASE)
|
||||
OWN_UID = os.environ.get("OWN_UID", os.environ["CIS_USER"])
|
||||
|
||||
app = FastAPI(title="CIS Enhanced")
|
||||
app.mount("/static", StaticFiles(directory=str(Path(__file__).parent / "static")), name="static")
|
||||
_STATIC_DIR = Path(__file__).parent / "static"
|
||||
app.mount("/static", StaticFiles(directory=str(_STATIC_DIR)), name="static")
|
||||
templates = Jinja2Templates(directory=str(Path(__file__).parent / "templates"))
|
||||
templates.env.globals["lv_color"] = lv_color
|
||||
templates.env.globals["decode_matrikel"] = decode_matrikel
|
||||
@@ -41,6 +43,19 @@ templates.env.globals["fmt_range"] = fmt_range
|
||||
templates.env.globals["week_label"] = week_label
|
||||
templates.env.globals["slots"] = SLOTS
|
||||
|
||||
# Cache-Busting: Version = Hash der JS/CSS-Inhalte (neue URL => kein veralteter Browser-Cache)
|
||||
_APP_HASH = hashlib.md5(
|
||||
(_STATIC_DIR / "app.js").read_bytes() + (_STATIC_DIR / "style.css").read_bytes()
|
||||
).hexdigest()[:10]
|
||||
templates.env.globals["app_version"] = _APP_HASH
|
||||
|
||||
|
||||
@app.middleware("http")
|
||||
async def _no_cache(request: Request, call_next):
|
||||
resp = await call_next(request)
|
||||
resp.headers["Cache-Control"] = "no-cache"
|
||||
return resp
|
||||
|
||||
|
||||
def _meta():
|
||||
return client.meta()
|
||||
|
||||
Reference in New Issue
Block a user