diff --git a/demo/fetch/node.ts b/demo/fetch/node.ts new file mode 100644 index 000000000..8e6be7bd9 --- /dev/null +++ b/demo/fetch/node.ts @@ -0,0 +1,10 @@ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ +import {fetch} from '@alwatr/fetch'; + +const response = await fetch({ + url: 'http://httpbin.org/uuid', + timeout: 3_000, + removeDuplicate: 'auto', +}); + +console.log(await response.text()); diff --git a/packages/core/fetch/src/fetch.ts b/packages/core/fetch/src/fetch.ts index ebe6bcd29..58ca076ac 100644 --- a/packages/core/fetch/src/fetch.ts +++ b/packages/core/fetch/src/fetch.ts @@ -89,7 +89,7 @@ export interface FetchOptions extends RequestInit { } let alwatrCacheStorage: Cache; -const cacheSupported = 'caches' in self; +const cacheSupported = 'caches' in globalThis; const duplicateRequestStorage: Record> = {}; @@ -389,7 +389,7 @@ function _handleTimeout(options: FetchOptions): Promise { }); }); - window + globalThis .fetch(options.url, options) .then((response) => resolved(response)) .catch((reason) => reject(reason))