Full document, spreadsheet, slideshow, and diagram tooling
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'fix: no-cache headers on express.static HTML responses' (#159) from fix/static-html-no-cache into main

scott d5202f05 6ad00045

+11 -3
+11 -3
server/index.ts
··· 431 431 res.sendFile(path.join(distPath, 'sw.js')); 432 432 }); 433 433 434 - app.use(express.static(distPath)); 434 + // HTML must never be HTTP-cached — ensures SW networkFirst gets fresh content on every deploy. 435 + // express.static serves /index.html, /docs/index.html etc. BEFORE the SPA fallback routes, 436 + // so we must set no-cache headers here too (not just on the fallback routes). 437 + const htmlNoCacheHeaders = { 'Cache-Control': 'no-cache, no-store, must-revalidate' }; 435 438 436 - // HTML pages must not be HTTP-cached — ensures SW networkFirst fetch gets fresh content 437 - const htmlNoCacheHeaders = { 'Cache-Control': 'no-cache, no-store, must-revalidate' }; 439 + app.use(express.static(distPath, { 440 + setHeaders: (res, filePath) => { 441 + if (filePath.endsWith('.html')) { 442 + res.set(htmlNoCacheHeaders); 443 + } 444 + }, 445 + })); 438 446 439 447 // SPA fallback: serve the correct index.html for each sub-app 440 448 app.get('/docs/:id', (_req: Request, res: Response) => { res.set(htmlNoCacheHeaders); res.sendFile(path.join(distPath, 'docs/index.html')); });