Enhance health check and inventory endpoints: include bridge connection status and web client count

This commit is contained in:
MayaTheShy
2026-03-21 19:26:36 -04:00
parent d1c9256ed8
commit b5ae28944d

View File

@@ -74,7 +74,13 @@ const server = createServer(app);
// Health check
app.get('/api/health', (req, res) => {
res.json({ status: 'ok', lastUpdate, uptime: process.uptime() });
res.json({
status: 'ok',
lastUpdate,
uptime: process.uptime(),
bridgeConnected: bridgeClients.size > 0,
webClients: webClients.size,
});
});
// Get current inventory state
@@ -89,6 +95,7 @@ app.get('/api/inventory', (req, res) => {
craftable: craftableRecipes,
craftTurtleOk,
lastUpdate,
bridgeConnected: bridgeClients.size > 0,
});
});
@@ -396,6 +403,7 @@ function updateStateFromBridge(data) {
craftable: craftableRecipes,
craftTurtleOk,
lastUpdate,
bridgeConnected: bridgeClients.size > 0,
});
// Persist to SQLite (debounced — won't block the broadcast)
@@ -489,6 +497,7 @@ wss.on('connection', (ws, req) => {
craftable: craftableRecipes,
craftTurtleOk,
lastUpdate,
bridgeConnected: bridgeClients.size > 0,
}));
ws.on('pong', () => { ws.isAlive = true; });