feat: Implement client-side version mismatch detection with reload prompt and add Nodemon for development.
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user