fix: auto-invalidate cache on version update — closes #121
- Add version check on app startup: compare server version with stored client version, clear all SW caches and reload on mismatch - Set Cache-Control: no-cache on index.html so browsers always fetch the latest version instead of serving stale cached HTML
This commit is contained in:
@@ -163,8 +163,16 @@ app.use('/api/backup', backupRoutes);
|
||||
// Serve static files in production
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
const publicPath = path.join(__dirname, '../public');
|
||||
app.use(express.static(publicPath));
|
||||
app.use(express.static(publicPath, {
|
||||
setHeaders: (res, filePath) => {
|
||||
// Never cache index.html so version updates are picked up immediately
|
||||
if (filePath.endsWith('index.html')) {
|
||||
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
||||
}
|
||||
},
|
||||
}));
|
||||
app.get('*', (req: Request, res: Response) => {
|
||||
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
||||
res.sendFile(path.join(publicPath, 'index.html'));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user