Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ssl: true,
xrd: true,
...opts
};
const scheme = config.ssl ? 'https://' : 'http://';
return promiseAny([
fetch(`${scheme}${config.host}/.well-known/host-meta.json`).then(async res => {
if (!res.ok) {
throw new Error('could-not-fetch-json');
}
return res.json();
}),
fetch(`${scheme}${config.host}/.well-known/host-meta`).then(async res => {
if (!res.ok) {
throw new Error('could-not-fetch-xml');
}
const data = await res.text();
const xml = JXT.parse(data);
if (xml) {
return registry.import(xml);
}
})
]);
}
) {
if (typeof opts === 'string') {
opts = { host: opts };
}
const config = {
json: true,
ssl: true,
xrd: true,
...opts
};
const scheme = config.ssl ? 'https://' : 'http://';
return promiseAny([
fetch(`${scheme}${config.host}/.well-known/host-meta.json`).then(async res => {
if (!res.ok) {
throw new Error('could-not-fetch-json');
}
return res.json();
}),
fetch(`${scheme}${config.host}/.well-known/host-meta`).then(async res => {
if (!res.ok) {
throw new Error('could-not-fetch-xml');
}
const data = await res.text();
const xml = JXT.parse(data);
if (xml) {
return registry.import(xml);
}
async function retryRequest(
url: string,
opts: RequestInit,
timeout: number,
allowedRetries: number = 5
): Promise {
let attempt = 0;
while (attempt <= allowedRetries) {
try {
const resp = await timeoutPromise(fetch(url, opts), timeout * 1000, () => {
return new Error('Request timed out');
});
if (!resp.ok) {
throw new Error('HTTP Status Error: ' + resp.status);
}
return resp.text();
} catch (err) {
attempt += 1;
if (attempt > allowedRetries) {
throw err;
}
}
await sleep(Math.pow(attempt, 2) * 1000);
}