-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
43 lines (38 loc) · 1.15 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import _fetch, {
Blob as _Blob,
File as _File,
FormData as _FormData,
Headers as _Headers,
Request as _Request,
Response as _Response
} from 'node-fetch'
import _AbortController from 'abort-controller'
// Hotfix for https://github.com/unjs/node-fetch-native/issues/10
const isStackblitz = process.env.SHELL === '/bin/jsh'
if (isStackblitz && !globalThis.fetch) {
// @ts-ignore
globalThis.fetch = (url: any, opts: any) => {
if (typeof url === 'string' && url.includes('//[::]')) {
url = url.replace('//[::]', '//0.0.0.0')
}
return fetch(url, opts)
}
}
export const fetch = globalThis.fetch || _fetch
export default fetch
export const Blob = globalThis.Blob || _Blob
export const File = globalThis.File || _File
export const FormData = globalThis.FormData || _FormData
export const Headers = globalThis.Headers || _Headers
export const Request = globalThis.Request || _Request
export const Response = globalThis.Response || _Response
export const AbortController = globalThis.AbortController || _AbortController
export {
AbortError,
FetchError,
blobFrom,
blobFromSync,
fileFrom,
fileFromSync,
isRedirect
} from 'node-fetch'