Auto-Reload bei neuem Build: no-cache index.html, build-time Check, SW skip-waiting
This commit is contained in:
@@ -82,8 +82,30 @@ app.get('/sw.js', (_req, res) => {
|
||||
res.sendFile(path.join(PUBLIC, 'sw.js'));
|
||||
});
|
||||
|
||||
app.use(express.static(PUBLIC));
|
||||
app.get('*', (_req, res) => res.sendFile(path.join(PUBLIC, 'index.html')));
|
||||
app.use(express.static(PUBLIC, {
|
||||
setHeaders: (res, filePath) => {
|
||||
// JS/CSS Assets haben Hash im Namen → lang cachen
|
||||
if (filePath.match(/\.(js|css)$/) && !filePath.includes('sw.js')) {
|
||||
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
// index.html nie cachen
|
||||
app.get('*', (_req, res) => {
|
||||
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
|
||||
res.setHeader('Pragma', 'no-cache');
|
||||
res.sendFile(path.join(PUBLIC, 'index.html'));
|
||||
});
|
||||
|
||||
// Build-Zeit Endpoint – Frontend prüft ob es eine neue Version gibt
|
||||
app.get('/api/build-time', (_req, res) => {
|
||||
res.setHeader('Cache-Control', 'no-store');
|
||||
try {
|
||||
const ver = require('fs').readFileSync(path.join(__dirname, '../version.txt'), 'utf8').trim();
|
||||
res.json({ buildTime: ver });
|
||||
} catch { res.json({ buildTime: 'unknown' }); }
|
||||
});
|
||||
|
||||
app.listen(4000, () => console.log('🚀 Dicken Dock läuft auf Port 4000'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user