From 9c85ed6fb68868b672f0a1b9776df876591c2d87 Mon Sep 17 00:00:00 2001 From: Deep Koluguri Date: Sat, 23 May 2026 23:06:03 -0400 Subject: [PATCH] fix: disable all browser caching for html files in node.js backend to prevent clients from hanging onto completely stale application layouts --- backend/server.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/server.js b/backend/server.js index 9e31f01..4d0a0c5 100644 --- a/backend/server.js +++ b/backend/server.js @@ -9,18 +9,35 @@ const port = 3000; app.use(express.json()); // Serve static files -app.use(express.static(path.join(__dirname, '../'))); +app.use(express.static(path.join(__dirname, '../'), { + setHeaders: (res, path) => { + if (path.endsWith('.html')) { + res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate'); + res.setHeader('Pragma', 'no-cache'); + res.setHeader('Expires', '0'); + } + } +})); // Primary Routes app.get('/', (req, res) => { + res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate'); + res.setHeader('Pragma', 'no-cache'); + res.setHeader('Expires', '0'); res.sendFile(path.join(__dirname, '../login.html')); }); app.get('/admin', (req, res) => { + res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate'); + res.setHeader('Pragma', 'no-cache'); + res.setHeader('Expires', '0'); res.sendFile(path.join(__dirname, '../admin.html')); }); app.get('/dashboard', (req, res) => { + res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate'); + res.setHeader('Pragma', 'no-cache'); + res.setHeader('Expires', '0'); res.sendFile(path.join(__dirname, '../dashboard.html')); });