// Frontend API client - calls our Express backend class FrontendApiClient { constructor() { this.baseUrl = ''; // Same origin as the current page } async getClusterMembers() { try { const response = await fetch('/api/cluster/members', { method: 'GET', headers: { 'Accept': 'application/json' } }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } return await response.json(); } catch (error) { throw new Error(`Request failed: ${error.message}`); } } async getNodeStatus(ip) { try { // Create a proxy endpoint that forwards the request to the specific node const response = await fetch(`/api/node/status/${encodeURIComponent(ip)}`, { method: 'GET', headers: { 'Accept': 'application/json' } }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } return await response.json(); } catch (error) { throw new Error(`Request failed: ${error.message}`); } } async getTasksStatus() { try { const response = await fetch('/api/tasks/status', { method: 'GET', headers: { 'Accept': 'application/json' } }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } return await response.json(); } catch (error) { throw new Error(`Request failed: ${error.message}`); } } } // Global client instance const client = new FrontendApiClient(); // Function to refresh cluster members async function refreshClusterMembers() { const container = document.getElementById('cluster-members-container'); // Store the currently expanded cards BEFORE showing loading state const expandedCards = new Map(); const existingCards = container.querySelectorAll('.member-card'); existingCards.forEach(card => { if (card.classList.contains('expanded')) { const memberIp = card.dataset.memberIp; const memberDetails = card.querySelector('.member-details'); if (memberDetails) { expandedCards.set(memberIp, memberDetails.innerHTML); console.log(`Storing expanded state for ${memberIp}`); } } }); console.log(`Stored ${expandedCards.size} expanded cards for restoration`); // Show loading state container.innerHTML = `