数通智联化工云平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.7 KiB

2 years ago
'use strict';
const http = require('node:http');
const https = require('node:https');
const nodeFetch = require('node-fetch-native');
2 years ago
const fetch$1 = require('./shared/ofetch.92c14be7.cjs');
2 years ago
require('destr');
require('ufo');
2 years ago
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
const http__default = /*#__PURE__*/_interopDefaultCompat(http);
const https__default = /*#__PURE__*/_interopDefaultCompat(https);
const nodeFetch__default = /*#__PURE__*/_interopDefaultCompat(nodeFetch);
2 years ago
function createNodeFetch() {
const useKeepAlive = JSON.parse(process.env.FETCH_KEEP_ALIVE || "false");
if (!useKeepAlive) {
2 years ago
return nodeFetch__default;
2 years ago
}
const agentOptions = { keepAlive: true };
2 years ago
const httpAgent = new http__default.Agent(agentOptions);
const httpsAgent = new https__default.Agent(agentOptions);
2 years ago
const nodeFetchOptions = {
agent(parsedURL) {
return parsedURL.protocol === "http:" ? httpAgent : httpsAgent;
}
};
return function nodeFetchWithKeepAlive(input, init) {
2 years ago
return nodeFetch__default(input, { ...nodeFetchOptions, ...init });
2 years ago
};
}
const fetch = globalThis.fetch || createNodeFetch();
const Headers = globalThis.Headers || nodeFetch.Headers;
2 years ago
const AbortController = globalThis.AbortController || nodeFetch.AbortController;
const ofetch = fetch$1.createFetch({ fetch, Headers, AbortController });
2 years ago
const $fetch = ofetch;
exports.FetchError = fetch$1.FetchError;
exports.createFetch = fetch$1.createFetch;
exports.createFetchError = fetch$1.createFetchError;
exports.$fetch = $fetch;
2 years ago
exports.AbortController = AbortController;
2 years ago
exports.Headers = Headers;
exports.createNodeFetch = createNodeFetch;
exports.fetch = fetch;
exports.ofetch = ofetch;