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

@@ -29,7 +29,7 @@ categorySyncer.on('synced', async ({ tree, unprunedTree, changed }) => {
traverse(unprunedTree);
//console.log(`🔍 Found ${imageIds.length} images and ${categoryIds.length} categories.`);
await pictureSyncer.syncImages(imageIds, 'categories');
await categoryProductsSyncer.syncProducts(categoryIds);
});

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 {

View File

@@ -7,7 +7,7 @@ const config = {
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
server: process.env.DB_HOST,
port: process.env.DB_PORT,
port: parseInt(process.env.DB_PORT, 10),
database: process.env.DB_DATABASE,
options: {
encrypt: false, // Adjust based on server config