fix(infra): bust the cached lex module that was actually the page

A reload kept using app.js?v=ee6ab2354fa3 from cache. That body was index.html, saved while every lex path was rewritten to the page, so the new router never saw a request. The script URL changed, and dossier responses are no-store so Gitea's six-hour asset cache cannot keep the wrong body.
This commit is contained in:
kert
2026-11-14 17:22:52 -05:00
parent f6c7b63a76
commit 2ed79ead74
2 changed files with 17 additions and 6 deletions

View File

@@ -22,9 +22,11 @@ so it follows them on every rebuild. The page inlines assets/css/fhirworx.css
the favicon set (assets/icons). The template uses only those tokens.
Cache: ``/*__VERSION__*/`` is the first 12 hex digits of a sha256 over the
sorted (name, bytes) of the ``*.js`` modules, stamped on the entry script
(``app.js?v=…``), so a new module set is a new URL; the modules it imports
revalidate through the ``dossier-nocache`` middleware.
sorted (name, bytes) of the ``*.js`` modules, plus ``CACHE_EPOCH``, stamped
on the entry script (``app.js?v=…``). The query string is the cache key.
``CACHE_EPOCH`` moved the key off a URL whose cached body was ``index.html``
(the lex catch-all rewrote every path there). Imported modules are not
stored: ``dossier-nocache`` sends ``Cache-Control: no-store``.
"""
from __future__ import annotations
@@ -107,12 +109,19 @@ def _fill(tpl: str, marker: str, value: str, count: int = 1) -> str:
return tpl.replace(marker, value)
# Bumped so browsers drop app.js?v=ee6ab2354fa3. That URL was cached as the
# HTML page while lex-page rewrote every path to index.html, and a reload
# kept using it without asking the server again.
CACHE_EPOCH = b"lex-assets\n"
def module_version(directory: Path) -> str:
"""sha256 over the sorted (name, bytes) of the directory's ``*.js``, [:12]."""
"""sha256 over CACHE_EPOCH and the sorted (name, bytes) of ``*.js``, [:12]."""
files = sorted(p for p in Path(directory).glob("*.js") if p.is_file())
if not files:
raise SystemExit(f"{directory}: no *.js modules")
h = hashlib.sha256()
h.update(CACHE_EPOCH)
for p in files:
data = p.read_bytes()
name = p.name.encode()

View File

@@ -63,11 +63,13 @@ http:
rewrites:
- regex: "</head>"
replacement: '<link rel="icon" type="image/png" sizes="32x32" href="//dashboard.{{ $domain }}/fav32.png"><link rel="stylesheet" type="text/css" href="//dashboard.{{ $domain }}/fhirworx.css"></head>'
# Gitea caches /assets/ for 6 h; the dossier page is rebuilt in place.
# Gitea sends public, max-age=21600 on /assets/. Replace it. A module
# URL once cached index.html under that lifetime, and reloads kept the
# cached body without asking again.
dossier-nocache:
headers:
customResponseHeaders:
Cache-Control: "no-cache"
Cache-Control: "no-store"
# lex.<domain> catch-all. Paths that are not a dossier module, the policy
# API, or the focus pane become the static page. lex-assets is a
# higher-priority router and must not use this middleware: the rewrite