Apply app updates automatically and survive proxy caching
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 29s
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 29s
- Check for a new service worker on every return to the foreground and every 30 minutes; apply it in the background or just after launch, never with unsynced edits or an open sheet. The Update prompt remains. - Register the worker at extension-less /sw (no-cache), so proxies that cache *.js regardless of headers cannot hide updates - Return 404 for missing files instead of the HTML shell - Tests for the static routes; smoke test covers /sw; document the Nginx Proxy Manager "Cache Assets" pitfall Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
bb0bc430aa
commit
8f6981c8a2
7 changed files with 190 additions and 40 deletions
|
|
@ -148,6 +148,15 @@ export function createApp({
|
|||
});
|
||||
app.use("/api", (_, res) => res.status(404).json({ error: "Not found" }));
|
||||
if (existsSync(dist)) {
|
||||
// The service worker is also served without a file extension. Reverse
|
||||
// proxies that cache by extension (e.g. Nginx Proxy Manager's "Cache
|
||||
// Assets") ignore no-cache on .js files, which hides app updates.
|
||||
app.get("/sw", (_, res) =>
|
||||
res
|
||||
.set("Cache-Control", "no-cache")
|
||||
.type("text/javascript")
|
||||
.sendFile(join(dist, "sw.js")),
|
||||
);
|
||||
app.use(
|
||||
express.static(dist, {
|
||||
maxAge: 0,
|
||||
|
|
@ -159,7 +168,13 @@ export function createApp({
|
|||
},
|
||||
}),
|
||||
);
|
||||
app.get("/{*path}", (_, res) => res.sendFile(join(dist, "index.html")));
|
||||
// Only app routes fall back to the shell. A missing file (an old build's
|
||||
// asset, say) must be a 404, never HTML that a cache could keep as script.
|
||||
app.get("/{*path}", (req, res) => {
|
||||
if (/\.[a-z0-9]+$/i.test(req.path))
|
||||
return res.status(404).type("text/plain").send("Not found");
|
||||
res.set("Cache-Control", "no-cache").sendFile(join(dist, "index.html"));
|
||||
});
|
||||
}
|
||||
app.use((error, _req, res, _next) =>
|
||||
res
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue