fix: no-cache headers on config+download endpoints, cache-bust config fetch from frontend

This commit is contained in:
root
2026-07-16 11:14:10 +00:00
parent 60a07e9ba8
commit 92291be2b1
4 changed files with 12 additions and 2 deletions

View File

@@ -135,6 +135,11 @@ router.get('/:templateId/config', (req, res) => {
return res.status(404).json({ error: 'Template file missing' });
}
// Prevent browser caching of the config — always return fresh config
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
res.setHeader('Pragma', 'no-cache');
res.setHeader('Expires', '0');
// Get file modification time for cache-busting doc key
const fileStats = fs.statSync(template.path);
const fileMtime = fileStats.mtimeMs;
@@ -235,6 +240,9 @@ router.get('/:templateId/download', (req, res) => {
const fileName = template.originalName || template.name + '.docx';
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');
res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`);
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
res.setHeader('Pragma', 'no-cache');
res.setHeader('Expires', '0');
const fileStream = fs.createReadStream(template.path);
fileStream.pipe(res);