Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/opencmo/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,19 @@ async def spa_catchall(request: Request, full_path: str = ""):
if spa_root in asset.parents and asset.exists() and asset.is_file():
import mimetypes
ct = mimetypes.guess_type(str(asset))[0] or "application/octet-stream"
return StreamingResponse(open(asset, "rb"), media_type=ct)
# Vite emits content-hashed files under assets/ — cache them
# forever. Other files (logo, contact-qr, etc.) can be swapped in
# place, so keep them revalidated.
cache_control = (
"public, max-age=31536000, immutable"
if full_path.startswith("assets/")
else "no-cache"
)
return StreamingResponse(
open(asset, "rb"),
media_type=ct,
headers={"Cache-Control": cache_control},
)

new_visitor_id: str | None = None
try:
Expand All @@ -1880,6 +1892,9 @@ async def spa_catchall(request: Request, full_path: str = ""):

# SPA fallback — always return index.html
response = HTMLResponse(rendered_html)
# The shell references content-hashed assets that change every build, so it
# must be revalidated to avoid serving a stale shell (blank page) post-deploy.
response.headers["Cache-Control"] = "no-cache"
if _is_app_surface(full_path):
response.headers["X-Robots-Tag"] = "noindex, nofollow, noarchive, nosnippet"
if new_visitor_id:
Expand Down
Loading