fix(backend): cache headers for the SPA — no-cache index.html, immutable hashed assets
Phones kept showing stale builds because index.html was served without cache headers; assets/* are content-hashed and safe to cache forever.
This commit is contained in:
+6
-2
@@ -52,8 +52,12 @@ async def spa(full_path: str):
|
||||
)
|
||||
candidate = (DIST / full_path).resolve() if full_path else None
|
||||
if candidate and candidate.is_file() and candidate.is_relative_to(DIST.resolve()):
|
||||
return FileResponse(candidate)
|
||||
return FileResponse(DIST / "index.html")
|
||||
# hashed assets are immutable; cache them hard
|
||||
headers = {"Cache-Control": "public, max-age=31536000, immutable"} \
|
||||
if full_path.startswith("assets/") else {"Cache-Control": "no-cache"}
|
||||
return FileResponse(candidate, headers=headers)
|
||||
# index.html must always revalidate, or phones keep showing stale builds
|
||||
return FileResponse(DIST / "index.html", headers={"Cache-Control": "no-cache"})
|
||||
|
||||
|
||||
# Catch-all WS route so the charger may dial any path (it uses /<ChargerID>).
|
||||
|
||||
Reference in New Issue
Block a user