diff options
author | 2021-09-09 23:33:34 -0700 | |
---|---|---|
committer | 2021-09-09 23:33:34 -0700 | |
commit | fc907e2f81698d89502fb2ee0375e6d98a492c13 (patch) | |
tree | e775c2479b334ec901f61b5c0ccfab0102ff679e /src/node-fallbacks | |
parent | 8a02ad48a5eb1319c1bf3e9eb97e013924db875f (diff) | |
download | bun-fc907e2f81698d89502fb2ee0375e6d98a492c13.tar.gz bun-fc907e2f81698d89502fb2ee0375e6d98a492c13.tar.zst bun-fc907e2f81698d89502fb2ee0375e6d98a492c13.zip |
currentjarred/fetch-experiment
Diffstat (limited to 'src/node-fallbacks')
-rw-r--r-- | src/node-fallbacks/@vercel_fetch.js | 11 | ||||
-rw-r--r-- | src/node-fallbacks/isomorphic-fetch.js | 2 | ||||
-rw-r--r-- | src/node-fallbacks/node-fetch.js | 2 |
3 files changed, 10 insertions, 5 deletions
diff --git a/src/node-fallbacks/@vercel_fetch.js b/src/node-fallbacks/@vercel_fetch.js index 5ab626670..95314ba9e 100644 --- a/src/node-fallbacks/@vercel_fetch.js +++ b/src/node-fallbacks/@vercel_fetch.js @@ -1,6 +1,8 @@ // This is just a no-op. Intent is to prevent importing a bunch of stuff that isn't relevant. -module.exports = (wrapper = Bun.fetch) => { - return async function vercelFetch(url, opts = {}) { +module.exports = ( + wrapper = "Bun" in globalThis ? Bun.fetch : globalThis.fetch +) => { + async function vercelFetch(url, opts = {}) { // Convert Object bodies to JSON if they are JS objects if ( opts.body && @@ -27,5 +29,8 @@ module.exports = (wrapper = Bun.fetch) => { err.opts = opts; throw err; } - }; + } + + vercelFetch.default = vercelFetch; + return vercelFetch; }; diff --git a/src/node-fallbacks/isomorphic-fetch.js b/src/node-fallbacks/isomorphic-fetch.js index 0bbe50ebf..96cbd72fb 100644 --- a/src/node-fallbacks/isomorphic-fetch.js +++ b/src/node-fallbacks/isomorphic-fetch.js @@ -1 +1 @@ -export default Bun.fetch; +export default "Bun" in globalThis ? Bun.fetch : globalThis.fetch; diff --git a/src/node-fallbacks/node-fetch.js b/src/node-fallbacks/node-fetch.js index 0bbe50ebf..96cbd72fb 100644 --- a/src/node-fallbacks/node-fetch.js +++ b/src/node-fallbacks/node-fetch.js @@ -1 +1 @@ -export default Bun.fetch; +export default "Bun" in globalThis ? Bun.fetch : globalThis.fetch; |