Files
bun.sh/src/js/thirdparty/vercel_fetch.js
dave caruso c2a77cf7ec Rewrite built-in modules to use CommonJS over ESM (#3814)
* stfdsafsd

sadffdsa

stuff

finish commonjs stuff

asdf

not done but work

not done but work

not done yet but this is how far i am

remove files

lol

update built files

uncomment everything in events lol

export default

stuff

* afdsafsd

* its not perfect but almost done

* okay

* cool

* remove temp file

* finish rebase

* revert settings.json

* a

* ch-ch-ch-ch-changes

* okay

* remove this check in release for now

* sxdcfghnjm,

* lkjhgf

* fmt

* filename can be null

* Update NodeModuleModule.h

* weee

* fmt

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2023-08-02 16:27:36 -07:00

33 lines
934 B
JavaScript

// This is just a no-op. Intent is to prevent importing a bunch of stuff that isn't relevant.
export default (wrapper = Bun.fetch) => {
async function vercelFetch(url, opts = {}) {
// Convert Object bodies to JSON if they are JS objects
if (
opts.body &&
typeof opts.body === "object" &&
(!("buffer" in opts.body) || typeof opts.body.buffer !== "object" || !(opts.body.buffer instanceof ArrayBuffer))
) {
opts.body = JSON.stringify(opts.body);
// Content length will automatically be set
if (!opts.headers) opts.headers = new Headers();
opts.headers.set("Content-Type", "application/json");
}
try {
return await wrapper(url, opts);
} catch (err) {
if (typeof err === "string") {
err = new Error(err);
}
err.url = url;
err.opts = opts;
throw err;
}
}
vercelFetch.default = vercelFetch;
return vercelFetch;
};