// Simulate what the Flutter app does console.log('Testing the fixed parsing logic...\n'); // Get auth token const authResp = await fetch('http://100.81.138.77:8000/api/v1/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: 'admin', password: 'admin123' }) }); const { access_token } = await authResp.json(); // Test all three endpoints const endpoints = [ { name: 'All Servers', url: 'http://100.81.138.77:8000/api/v1/configuration/servers' }, { name: 'G-Core', url: 'http://100.81.138.77:8000/api/v1/configuration/servers/gcore' }, { name: 'GeViScope', url: 'http://100.81.138.77:8000/api/v1/configuration/servers/geviscope' } ]; for (const endpoint of endpoints) { console.log(`Testing: ${endpoint.name}`); const resp = await fetch(endpoint.url, { headers: { 'Authorization': `Bearer ${access_token}` } }); const data = await resp.json(); // Simulate Flutter parsing if (endpoint.name === 'All Servers') { // This one returns { gcore_servers: [], geviscope_servers: [] } const gcoreServers = data.gcore_servers || []; const geviscopeServers = data.geviscope_servers || []; console.log(` ✅ Parsed ${gcoreServers.length} G-Core + ${geviscopeServers.length} GeViScope servers`); } else { // These return { servers: [], total: N } if (Array.isArray(data)) { console.log(` ❌ ERROR: Got array directly (old behavior)`); } else if (data.servers && Array.isArray(data.servers)) { console.log(` ✅ Parsed ${data.servers.length} servers from object.servers`); } else { console.log(` ❌ ERROR: Unexpected structure:`, Object.keys(data)); } } console.log(''); } console.log('='.repeat(60)); console.log('All endpoints return objects as expected!'); console.log('The Flutter code should now handle them correctly.');