36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
|
||
/* --------------------------------------------------
|
||
1. Expose the API URL (identical to PHP’s $apiUrl)
|
||
-------------------------------------------------- */
|
||
const API_URL = 'http://<?= h($api_bind_ip) ?>:<?= h($customApiPort) ?>/php_summary';
|
||
|
||
/* --------------------------------------------------
|
||
2. Build the endpoint list
|
||
-------------------------------------------------- */
|
||
document.addEventListener('DOMContentLoaded', () => {
|
||
const listEl = document.getElementById('endpointList');
|
||
const urlParam = new URLSearchParams(window.location.search);
|
||
const current = urlParam.get('host'); // e.g. "MC-CM3588"
|
||
|
||
fetch(API_URL)
|
||
.then(r => r.json())
|
||
.then(hosts => {
|
||
hosts.forEach(hostObj => {
|
||
const li = document.createElement('li');
|
||
const a = document.createElement('a');
|
||
|
||
a.href = '?host=' + encodeURIComponent(hostObj.hostname);
|
||
a.textContent = hostObj.hostname;
|
||
if (hostObj.hostname === current) a.classList.add('active');
|
||
|
||
li.appendChild(a);
|
||
listEl.appendChild(li);
|
||
});
|
||
})
|
||
.catch(err => {
|
||
console.error('Failed to load endpoint list:', err);
|
||
const li = document.createElement('li');
|
||
li.textContent = 'Unable to load endpoints';
|
||
listEl.appendChild(li);
|
||
});
|
||
}); |