diff --git a/web/server/server.js b/web/server/server.js index 048c791..e9f3374 100644 --- a/web/server/server.js +++ b/web/server/server.js @@ -4,7 +4,8 @@ import cors from 'cors'; import { createServer } from 'http'; const app = express(); -const PORT = 3001; +const PORT = process.env.PORT || 3001; +const HOST = process.env.HOST || '0.0.0.0'; app.use(cors()); app.use(express.json({ limit: '5mb' })); @@ -282,8 +283,16 @@ app.post('/api/bridge/result', (req, res) => { function updateStateFromBridge(data) { if (data.cache) { + // Normalize itemList: Lua sends { name, total }, frontend expects { name, count } + const rawItems = data.cache.itemList || []; + const normalizedItems = rawItems.map(item => ({ + name: item.name, + count: item.total !== undefined ? item.total : (item.count || 0), + displayName: item.displayName || item.name, + })); + inventoryState = { - itemList: data.cache.itemList || [], + itemList: normalizedItems, grandTotal: data.cache.grandTotal || 0, chestCount: data.cache.chestCount || 0, totalSlots: data.cache.totalSlots || 0, @@ -420,8 +429,8 @@ wss.on('connection', (ws, req) => { // ========== Start Server ========== -server.listen(PORT, () => { - console.log(`✅ Inventory Manager Web Server ready on port ${PORT}`); +server.listen(PORT, HOST, () => { + console.log(`✅ Inventory Manager Web Server ready on ${HOST}:${PORT}`); console.log(`\nBridge HTTP endpoint: http://localhost:${PORT}/api/bridge/state`); console.log(`Bridge WebSocket: ws://localhost:${PORT}/ws/bridge`); console.log(`Web client WebSocket: ws://localhost:${PORT}/ws`);