Skip to content

Commit fe77e7a

Browse files
committed
fix: add hotfix for stackblitz support (#10)
1 parent 87aeaea commit fe77e7a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ import _fetch, {
99

1010
import _AbortController from 'abort-controller'
1111

12+
// Hotfix for https://github.com/unjs/node-fetch-native/issues/10
13+
const isStackblitz = process.env.SHELL === '/bin/jsh'
14+
if (isStackblitz && !globalThis.fetch) {
15+
// @ts-ignore
16+
globalThis.fetch = (url: any, opts: any) => {
17+
if (typeof url === 'string' && url.includes('//[::]')) {
18+
url = url.replace('//[::]', '//0.0.0.0')
19+
}
20+
return fetch(url, opts)
21+
}
22+
}
23+
1224
export const fetch = globalThis.fetch || _fetch
1325
export default fetch
1426

0 commit comments

Comments
 (0)