Skip to content

Commit

Permalink
fix: add hotfix for stackblitz support (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 20, 2022
1 parent 87aeaea commit fe77e7a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/index.ts
Expand Up @@ -9,6 +9,18 @@ import _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

Expand Down

0 comments on commit fe77e7a

Please sign in to comment.