Urara-Blog/node_modules/.pnpm-store/v3/files/da/0fbf2b9fd0a771390677cb7dc05eb03c11480bde02632a7a8fbaacfcb90b780c684ea9eacbb7459a1cd704b06a1b5a4a08f5f97d94683ee646b80edfb602c1
2022-08-14 01:14:53 +08:00

30 lines
1 KiB
Text

import http from 'http';
import https from 'https';
import nodeFetch, { Headers as Headers$1 } from 'node-fetch-native';
import { c as createFetch } from './chunks/fetch.mjs';
export { F as FetchError, c as createFetch, a as createFetchError } from './chunks/fetch.mjs';
import 'destr';
import 'ufo';
function createNodeFetch() {
const useKeepAlive = JSON.parse(process.env.FETCH_KEEP_ALIVE || "false");
if (!useKeepAlive) {
return nodeFetch;
}
const agentOpts = { keepAlive: true };
const httpAgent = new http.Agent(agentOpts);
const httpsAgent = new https.Agent(agentOpts);
const nodeFetchOptions = {
agent(parsedURL) {
return parsedURL.protocol === "http:" ? httpAgent : httpsAgent;
}
};
return function nodeFetchWithKeepAlive(input, init) {
return nodeFetch(input, { ...nodeFetchOptions, ...init });
};
}
const fetch = globalThis.fetch || createNodeFetch();
const Headers = globalThis.Headers || Headers$1;
const $fetch = createFetch({ fetch, Headers });
export { $fetch, Headers, createNodeFetch, fetch };