// Debug version of middleware const fs = require('fs'); const path = require('path'); function createCacheBustingMiddleware(version) { return function cacheBustingMiddleware(req, res, next) { console.log('[MIDDLEWARE] Request for:', req.path); const originalSendFile = res.sendFile.bind(res); res.sendFile = function(filePath, options, callback) { console.log('[MIDDLEWARE] sendFile called with:', filePath); console.log('[MIDDLEWARE] File extension check:', path.extname(filePath)); if (filePath && (filePath.endsWith('.html') || filePath.endsWith('.htm'))) { console.log('[MIDDLEWARE] Processing HTML file'); try { const data = fs.readFileSync(filePath, 'utf8'); console.log('[MIDDLEWARE] File read successfully, length:', data.length); // Simple test: add comment const modifiedHtml = data.replace('', '\n'); res.setHeader('Content-Type', 'text/html; charset=utf-8'); res.send(modifiedHtml); if (callback) callback(); } catch (err) { console.error('[MIDDLEWARE] Error:', err); return originalSendFile(filePath, options, callback); } } else { console.log('[MIDDLEWARE] Not an HTML file, using original'); return originalSendFile(filePath, options, callback); } }; next(); }; } module.exports = { createCacheBustingMiddleware };