feat(persist): salva stato su .segnapunti/state.json ad ogni azione

All'avvio il server carica lo stato dal file se esiste; ad ogni azione
lo riscrive. Il riavvio del server riprende dall'ultimo punto salvato.
This commit is contained in:
2026-05-12 14:08:06 +02:00
parent 0ba49ead5d
commit 15dac9f965
4 changed files with 32 additions and 3 deletions
+2 -1
View File
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'url'
import { dirname, join } from 'path'
import { setupWebSocketHandler } from './src/websocket-handler.js'
import { printServerInfo } from './src/server-utils.js'
import { loadState, saveState } from './src/persist.js'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
@@ -26,7 +27,7 @@ app.get(['/controller', '/controller/*splat'], (_req, res) => {
const server = createServer(app)
const wss = new WebSocketServer({ noServer: true })
setupWebSocketHandler(wss)
setupWebSocketHandler(wss, { initialState: loadState(), onStateChange: saveState })
server.on('upgrade', (request, socket, head) => {
const pathname = new URL(request.url, `http://${request.headers.host}`).pathname