Changeset fcd6964 in Klonkt for src/routes/guardian.js
- Timestamp:
- 07/24/2026 08:59:51 PM (7 weeks ago)
- Branches:
- main
- Children:
- c6185fa
- Parents:
- 3ffbedd
- File:
-
- 1 edited
-
src/routes/guardian.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/guardian.js
r3ffbedd rfcd6964 10 10 */ 11 11 import express from 'express'; 12 import fs from 'fs';13 12 import path from 'path'; 14 13 import { fileURLToPath } from 'url'; … … 20 19 21 20 const router = express.Router(); 22 23 // Cache-bust the PWA assets: /assets is served with a 1-year cache, so without24 // a per-build version the browser keeps running an old guardian.js/css after a25 // deploy (that was exactly the "no feedback / not arriving" bug). The version26 // is the file's mtime at process start; a redeploy restarts us and bumps it.27 21 const __dir = path.dirname(fileURLToPath(import.meta.url)); 28 function assetVersion(rel) {29 try { return Math.floor(fs.statSync(path.join(__dir, '..', 'assets', rel)).mtimeMs).toString(36); }30 catch { return '0'; }31 }32 const ASSET_V = { js: assetVersion('js/guardian.js'), css: assetVersion('css/guardian.css') };33 22 34 23 /** The acting site: ?site=slug when owned, else the user's first site. */ … … 78 67 sites, 79 68 lang: L, 80 assetV: ASSET_V,81 69 t: (k, v) => i18nT(L, k, v), 82 70 cspNonce: res.locals.cspNonce, … … 125 113 res.json({ ok: true, committed: !!r.committed, readyToCommit: !!r.readyToCommit }); 126 114 }); 115 116 // ── PWA assets served no-cache, so an update is never masked by the 1-year 117 // /assets cache or a stuck install (that was the whole "nothing works after 118 // a deploy" bug). Small files; the browser revalidates and gets a 304 when 119 // unchanged, the fresh file when changed. 120 function pwaAsset(rel, type) { 121 return (req, res) => { 122 res.set('Cache-Control', 'no-cache'); 123 res.type(type); 124 res.sendFile(path.join(__dir, '..', 'assets', rel)); 125 }; 126 } 127 router.get('/app.js', pwaAsset('js/guardian.js', 'application/javascript')); 128 router.get('/app.css', pwaAsset('css/guardian.css', 'text/css')); 127 129 128 130 // ── Manage: release a committed ward (local Undo; federation is Fase 4). ──
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)