From fe77e7a02c5778e87d487b8a37e0d15c61ef10f7 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 20 Sep 2022 22:27:51 +0200 Subject: [PATCH] fix: add hotfix for stackblitz support (#10) --- src/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/index.ts b/src/index.ts index 41b5a72..72de00f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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