Spaces:
Sleeping
Sleeping
File size: 608 Bytes
6655e35 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import * as nodeFetch from 'node-fetch';
export default (typeof globalThis.fetch === 'function'
? // The Fetch API is supported experimentally in Node 17.5+ and natively in Node 18+.
globalThis.fetch
: // Otherwise use the polyfill.
async function (
input: nodeFetch.RequestInfo,
init?: nodeFetch.RequestInit,
): Promise<nodeFetch.Response> {
const processedInput =
typeof input === 'string' && input.slice(0, 2) === '//'
? 'https:' + input
: input;
return await nodeFetch.default(processedInput, init);
}) as typeof globalThis.fetch;
|