You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
|
|
|
|
elem = document.getElementsByTagName('table')[0];
|
|
|
|
getnodes();
|
|
async function getnodes() {
|
|
let config = await fetch(api_url + 'config').
|
|
then(resp => resp.json()).
|
|
then(obj => { return obj.config }).
|
|
catch(console.error);
|
|
console.log('nodes.config:',config);
|
|
|
|
let n = 1;
|
|
let list = '<ul>';
|
|
let nodes = [];
|
|
for (node of config.nodes) {
|
|
console.log('nodes.node:',node);
|
|
let [ip,port] = node.split(':');
|
|
let info = await get_info(node);
|
|
nodes.push(info);
|
|
let url=`http://${node}`;
|
|
let status='offline';
|
|
let info_url = `${url}${api_url}getinfo`;
|
|
list += `<li>node${n} (:${port}) <a href="${url}">${node}</a> ${status} <a href="${info_url}">information</a></li>\n`;
|
|
console.log('nodes.info:',info);
|
|
n++;
|
|
}
|
|
list += '</ul>';
|
|
let elem = document.getElementById('list');
|
|
elem.innerHTML = list;
|
|
return nodes;
|
|
}
|
|
function get_info(node) {
|
|
let [ip,port] = node.split(':');
|
|
let remote_api_url = `http://${node}${api_url}`;
|
|
let promised = fetch(remote_api_url + 'getinfo').
|
|
then(resp => resp.json).
|
|
then(obj => { let info = obj.info; return info; }).
|
|
catch(console.error);
|
|
return promised;
|
|
}
|
|
|
|
|
|
|
|
console.log('peerid.js loaded');
|