Force requests over IPv4

This commit is contained in:
Romein van Buren 2022-07-15 17:28:30 +02:00
parent 40309edc1f
commit 8ef7122811
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49

View File

@ -3,6 +3,12 @@
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const { operators } = require('./operators'); const { operators } = require('./operators');
const { realValues } = require('./realvalues'); const { realValues } = require('./realvalues');
const http = require('http');
const https = require('https');
// Force requests over IPv4
const httpAgent = new http.Agent({ family: 4 });
const httpsAgent = new https.Agent({ family: 4 });
async function testEndpoints(endpoints) { async function testEndpoints(endpoints) {
const output = { const output = {
@ -20,7 +26,15 @@ async function testEndpoints(endpoints) {
return obj; return obj;
}, {}); }, {});
const res = await fetch(endpoint.uri, { headers }); const res = await fetch(endpoint.uri, {
headers,
agent: url => {
if (url.protocol === 'http:') {
return httpAgent;
}
return httpsAgent;
},
});
const body = await res.text(); const body = await res.text();
endpoint.requirements.forEach(requirement => { endpoint.requirements.forEach(requirement => {