feat: Implement client-side version mismatch detection with reload prompt and add Nodemon for development.

This commit is contained in:
sebseb7
2025-11-24 11:04:45 +01:00
parent 3f7dc21d35
commit c1209a8048
9 changed files with 434 additions and 9 deletions

View File

@@ -11,7 +11,13 @@ export function registerIndex(app, cache) {
res.set('ETag', cache.html.etag);
res.set('Content-Type', 'text/html');
res.send(cache.html.data);
// Inject ETag into HTML as meta tag
const htmlWithEtag = cache.html.data.replace(
'<head>',
`<head>\n <meta name="app-version" content="${cache.html.etag}">`
);
res.send(htmlWithEtag);
} catch (err) {
console.error('Error serving index.html:', err);
res.status(500).send('Error loading page');

View File

@@ -99,7 +99,7 @@ export function startServer(categorySyncer, categoryProductsSyncer) {
}
// Register socket connection handler
registerConnection(io, CACHE_DIR);
registerConnection(io, CACHE_DIR, cache);
// Register routes
registerCategories(app, cache);

View File

@@ -1,9 +1,17 @@
import { findMatches } from '../utils/search-helper.js';
export function registerConnection(io, cacheDir) {
export function registerConnection(io, cacheDir, cache) {
io.on('connection', (socket) => {
console.log('🔌 Client connected');
socket.on('checkVersion', (clientEtag) => {
const serverEtag = cache.html.etag;
if (clientEtag !== serverEtag) {
console.log(`⚠️ Version mismatch - Client: ${clientEtag}, Server: ${serverEtag}`);
socket.emit('versionMismatch', { serverEtag });
}
});
socket.on('search', async (query) => {
// console.log(`🔍 Search request: "${query}"`);
try {