From 362eaadeb0062162d5c49524971bb67644a935ac Mon Sep 17 00:00:00 2001 From: Daniel Onyejesi Date: Sat, 21 Mar 2026 23:54:48 -0400 Subject: [PATCH] Fix: set no-cache headers for HTML, short cache for JS/CSS Prevents Caddy/browser from caching index.html across deployments. --- server.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 86a78ec..99945b6 100644 --- a/server.js +++ b/server.js @@ -84,7 +84,19 @@ app.use('/api/auth/forgot-password', rateLimit({ })); app.use(loggingMiddleware); -app.use(express.static(path.join(__dirname, 'public'))); +app.use(express.static(path.join(__dirname, 'public'), { + setHeaders: (res, filePath) => { + if (filePath.endsWith('.html')) { + // Never cache HTML — ensures new deployments are picked up immediately + res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); + res.setHeader('Pragma', 'no-cache'); + res.setHeader('Expires', '0'); + } else if (filePath.match(/\.(js|css)$/)) { + // Short cache for JS/CSS — 1 hour + res.setHeader('Cache-Control', 'public, max-age=3600'); + } + } +})); // Routes app.use('/api/auth', require('./src/routes/auth')); @@ -115,7 +127,12 @@ app.get('/api/health', (req, res) => { }); }); -app.get('*', (req, res) => res.sendFile(path.join(__dirname, 'public', 'index.html'))); +app.get('*', (req, res) => { + res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); + res.setHeader('Pragma', 'no-cache'); + res.setHeader('Expires', '0'); + res.sendFile(path.join(__dirname, 'public', 'index.html')); +}); const PORT = process.env.PORT || 3000; server.listen(PORT, () => {