fix: no-cache headers on config+download endpoints, cache-bust config fetch from frontend
This commit is contained in:
Binary file not shown.
@@ -6,6 +6,6 @@
|
||||
"originalName": "master_cv_template.docx",
|
||||
"path": "/root/workspace/cv-app/renderer/carbone-templates/433a0593-d3cf-414e-8763-ab5f87cbc75c.docx",
|
||||
"uploadedAt": "2026-07-16T09:03:29.601Z",
|
||||
"updatedAt": "2026-07-16T11:09:51.737Z"
|
||||
"updatedAt": "2026-07-16T11:12:12.609Z"
|
||||
}
|
||||
]
|
||||
@@ -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);
|
||||
|
||||
@@ -264,7 +264,9 @@ async function loadOnlyofficeTemplates() {
|
||||
async function openOnlyofficeEditor(templateId, templateName) {
|
||||
try {
|
||||
// Get the JWT-signed editor config from our backend
|
||||
const resp = await fetch(ONLYOFFICE_API + '/' + templateId + '/config');
|
||||
// Add cache-buster to prevent browser caching the old config
|
||||
const cacheBuster = Date.now();
|
||||
const resp = await fetch(ONLYOFFICE_API + '/' + templateId + '/config?cb=' + cacheBuster);
|
||||
if (!resp.ok) {
|
||||
const err = await resp.json();
|
||||
throw new Error(err.error || 'Failed to get editor config');
|
||||
|
||||
Reference in New Issue
Block a user