From cfc9514ef0b22fb1ae156becf31caa3e3c57b951 Mon Sep 17 00:00:00 2001 From: "courtmanr@gmail.com" Date: Thu, 24 Apr 2025 23:05:59 +0100 Subject: [PATCH] fix(server): Resolve ReferenceErrors in /api/storage and socket requestData --- server/index.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/server/index.js b/server/index.js index cbf49bb9e..fbb807e9d 100644 --- a/server/index.js +++ b/server/index.js @@ -478,11 +478,9 @@ app.get('/api/version', (req, res) => { app.get('/api/storage', async (req, res) => { try { - // Reuse the fetchStorageDetailsForAllNodes logic or similar - // This might need adjustment based on where fetchStorageDetailsForAllNodes is defined/refactored - // For now, assuming it returns the expected structure or throws an error - const storageData = await fetchStorageDetailsForAllNodes(endpoints); // Pass configured endpoints - res.json(storageData); + // Return the current node data which includes storage information + // TODO: Consider filtering/transforming this data specifically for storage endpoint if needed + res.json({ nodes: currentNodes }); // Return current node state } catch (error) { console.error("Error in /api/storage:", error); res.status(500).json({ globalError: error.message || "Failed to fetch storage details." }); @@ -508,14 +506,19 @@ io.on('connection', (socket) => { socket.on('requestData', async () => { console.log('Client requested data'); try { - // Send cached data immediately - if (globalApiCache) { - socket.emit('rawData', globalApiCache); + // Send the current known state immediately + if (currentNodes.length > 0 || currentVms.length > 0 || currentContainers.length > 0 || pbsDataArray.length > 0) { + socket.emit('rawData', { + nodes: currentNodes, + vms: currentVms, + containers: currentContainers, + metrics: currentMetrics, + pbs: pbsDataArray + }); } else { - console.log('No cached data available on request, waiting for next cycle.'); - // Optionally trigger an immediate discovery/metric cycle? - // await runDiscoveryCycle(); // Be careful with triggering cycles on demand - // if (globalApiCache) socket.emit('rawData', globalApiCache); + console.log('No data available yet on request, waiting for next cycle.'); + // Optionally trigger an immediate discovery cycle? + // runDiscoveryCycle(); // Be careful with triggering cycles on demand } } catch (error) { console.error('Error fetching data on client request:', error);