1const servers = [ 2 'usa-1.poxel.io', 3 'usa-2.poxel.io', 4 'usa-3.poxel.io', 5 'fra-1.poxel.io', 6 'fra-2.poxel.io', 7 'asia-1.poxel.io' 8]; 9 10function getRandomServer() { 11 return servers[Math.floor(Math.random() * servers.length)]; 12} 13 14async function fetchBestRegion() { 15 const maxAttempts = 3; 16 for (let attempt = 1; attempt <= maxAttempts; attempt++) { 17 const randomServer = getRandomServer(); 18 try { 19 const response = await fetch(`https://${randomServer}/api/init`); 20 if (response.ok) { 21 const data = await response.json(); 22 const bestRegion = data.region; // use the "region" from the response JSON 23 console.log(`Attempt ${attempt}: Best region from server ${randomServer}: ${bestRegion}`); 24 return bestRegion; 25 } else { 26 console.error(`Attempt ${attempt}: Server ${randomServer} responded with status: ${response.status}`); 27 } 28 } catch (error) { 29 console.error(`Attempt ${attempt}: Error fetching best region from ${randomServer}:`, error); 30 } 31 } 32 console.error('All attempts failed. Falling back to default: USA'); 33 return 'USA'; 34} 35 36const cachedBestServer = localStorage.getItem('bestServer'); 37 38if (!cachedBestServer) { 39 fetchBestRegion().then(bestRegion => { 40 console.log('Best region to connect (Saving to localStorage):', bestRegion); 41 localStorage.setItem('bestServer', bestRegion); 42 }).catch(error => { 43 console.error('Error during region fetching:', error); 44 }); 45} else { 46 console.log('Using cached best server:', cachedBestServer); 47}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.