chatgpt-api/src/fetch.ts

23 wiersze
542 B
TypeScript
Czysty Zwykły widok Historia

/// <reference lib="dom" />
let _undici: any
// Use `undici` for node.js 16 and 17
// Use `fetch` for node.js >= 18
2022-12-07 04:07:14 +00:00
// Use `fetch` for all other environments, including browsers
// NOTE: The top-level await is removed in a `postbuild` npm script for the
// browser build
const fetch =
globalThis.fetch ??
async function undiciFetchWrapper(
...args: Parameters<typeof globalThis.fetch>
): Promise<Response> {
if (!_undici) {
_undici = await import('undici')
}
return _undici.fetch(...args)
}
export { fetch }