feat: implement user authentication and login modal, refactor backend
This commit is contained in:
41
web/backend/services/fileWatcher.js
Normal file
41
web/backend/services/fileWatcher.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { watch } from 'chokidar';
|
||||
import { existsSync } from 'fs';
|
||||
import { PATHS } from '../config/constants.js';
|
||||
import { readJSON } from '../utils/fileUtils.js';
|
||||
import { broadcast } from './websocket.js';
|
||||
|
||||
let watcher = null;
|
||||
|
||||
// Inicializar file watcher
|
||||
export function initFileWatcher() {
|
||||
// Watch files for changes
|
||||
const filesToWatch = [PATHS.WORKERS].filter(p => existsSync(p));
|
||||
|
||||
if (filesToWatch.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
watcher = watch(filesToWatch, {
|
||||
persistent: true,
|
||||
ignoreInitial: true,
|
||||
});
|
||||
|
||||
watcher.on('change', async (path) => {
|
||||
console.log(`Archivo cambiado: ${path}`);
|
||||
if (path === PATHS.WORKERS) {
|
||||
const workers = readJSON(PATHS.WORKERS);
|
||||
broadcast({ type: 'workers_updated', data: workers });
|
||||
}
|
||||
});
|
||||
|
||||
console.log('✅ File watcher inicializado');
|
||||
}
|
||||
|
||||
// Detener file watcher
|
||||
export function stopFileWatcher() {
|
||||
if (watcher) {
|
||||
watcher.close();
|
||||
watcher = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user