mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Updated stream.js to use fetch api. (#345)
This commit is contained in:
5
test/vm-cluster/package-lock.json
generated
5
test/vm-cluster/package-lock.json
generated
@@ -310,6 +310,11 @@
|
||||
"mime-db": "1.48.0"
|
||||
}
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
|
||||
},
|
||||
"oauth-sign": {
|
||||
"version": "0.9.0",
|
||||
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"azure-storage": "2.10.4",
|
||||
"blake3": "2.1.4",
|
||||
"libsodium-wrappers": "0.7.6",
|
||||
"ws": "7.1.2"
|
||||
"ws": "7.1.2",
|
||||
"node-fetch": "2.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ const HotPocket = require('../../examples/js_client/lib/hp-client-lib');
|
||||
const azure = require('azure-storage');
|
||||
const fs = require('fs');
|
||||
const https = require('https');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
const dispatchInterval = process.env.DISPATCH || 1000;
|
||||
const stateUploadInterval = process.env.STATEUPLOAD || 10000;
|
||||
@@ -264,35 +265,19 @@ async function reportEvent(node, ev) {
|
||||
|
||||
function getVultrHosts(group) {
|
||||
|
||||
return new Promise(resolve => {
|
||||
return new Promise(async (resolve) => {
|
||||
|
||||
if (!group || group.trim().length == 0)
|
||||
resolve([]);
|
||||
|
||||
const req = https.request({
|
||||
hostname: 'api.vultr.com',
|
||||
port: 443,
|
||||
path: `/v2/instances?tag=${group}`,
|
||||
const resp = await fetch(`https://api.vultr.com/v2/instances?tag=${group}`, {
|
||||
method: 'GET',
|
||||
headers: { "Authorization": `Bearer ${vultrApiKey}` }
|
||||
}, res => {
|
||||
if (res.statusCode >= 200 && res.statusCode < 300)
|
||||
res.on('data', d => {
|
||||
// Sort vms by label.
|
||||
const vms = JSON.parse(d).instances;
|
||||
const ips = vms.sort((a, b) => (a.label < b.label) ? -1 : 1).map(i => i.main_ip);
|
||||
resolve(ips)
|
||||
});
|
||||
else
|
||||
resolve([]);
|
||||
})
|
||||
|
||||
req.on('error', error => {
|
||||
console.error(error);
|
||||
resolve([]);
|
||||
})
|
||||
|
||||
req.end();
|
||||
});
|
||||
|
||||
const vms = (await resp.json()).instances;
|
||||
const ips = vms.sort((a, b) => (a.label < b.label) ? -1 : 1).map(i => i.main_ip);
|
||||
resolve(ips);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user