Fix: /update-Endpunkt zum manuellen SW-Cache-Reset + STATIC_ASSETS bereinigt

/update loescht SW + alle Caches via JS und leitet zur App zurueck.
Alter SW hat /update nie gecacht -> immer frisch vom Server.
STATIC_ASSETS ohne ?v= (verhindert fehlerhafte cache.addAll()-Fehler).
This commit is contained in:
rene 2026-04-14 17:33:12 +02:00
parent 619ff559e6
commit 1c6ec6f17e
2 changed files with 48 additions and 5 deletions

View file

@ -129,6 +129,49 @@ async def share_target(request: Request):
headers={"Cache-Control": "no-cache"} headers={"Cache-Control": "no-cache"}
) )
# Cache-Reset-Seite — löscht SW + Caches, leitet zur App weiter
@app.get("/update")
async def force_update():
from fastapi.responses import HTMLResponse
html = """<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ban Yaro Aktualisieren</title>
<style>
body{font-family:-apple-system,sans-serif;display:flex;align-items:center;
justify-content:center;min-height:100vh;margin:0;background:#faf8f5}
.box{text-align:center;padding:2rem}
h1{color:#C4843A;margin-bottom:.5rem}
p{color:#666;margin-bottom:1.5rem}
.sp{width:44px;height:44px;border:4px solid #eee;border-top-color:#C4843A;
border-radius:50%;animation:s .8s linear infinite;margin:0 auto}
@keyframes s{to{transform:rotate(360deg)}}
</style>
</head>
<body>
<div class="box">
<h1>Ban Yaro</h1>
<p>App wird aktualisiert&#8230;</p>
<div class="sp"></div>
</div>
<script>
(async () => {
if ('serviceWorker' in navigator) {
const regs = await navigator.serviceWorker.getRegistrations();
await Promise.all(regs.map(r => r.unregister()));
}
const keys = await caches.keys();
await Promise.all(keys.map(k => caches.delete(k)));
window.location.replace('/');
})();
</script>
</body>
</html>"""
return HTMLResponse(html, headers={"Cache-Control": "no-store"})
# SPA Fallback — ALLE nicht-API-Routen gehen zur index.html # SPA Fallback — ALLE nicht-API-Routen gehen zur index.html
@app.get("/{full_path:path}") @app.get("/{full_path:path}")
async def spa_fallback(full_path: str): async def spa_fallback(full_path: str):

View file

@ -9,11 +9,11 @@ const CACHE_STATIC = `${CACHE_VERSION}-static`;
// index.html wird NICHT pre-gecacht (immer Network-First) // index.html wird NICHT pre-gecacht (immer Network-First)
const STATIC_ASSETS = [ const STATIC_ASSETS = [
'/css/design-system.css', '/css/design-system.css',
'/css/layout.css?v=32', '/css/layout.css',
'/css/components.css?v=32', '/css/components.css',
'/js/api.js?v=32', '/js/api.js',
'/js/ui.js?v=32', '/js/ui.js',
'/js/app.js?v=32', '/js/app.js',
'/manifest.json', '/manifest.json',
'/icons/icon-192.png', '/icons/icon-192.png',
]; ];