mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
* Add a zig fmt action * add failing file * Setup prettier better * Update prettier-fmt.yml * Fail on error * Update prettier-fmt.yml * boop * boop2 * tar.gz * Update zig-fmt.yml * Update zig-fmt.yml * Update zig-fmt.yml * Update zig-fmt.yml * Update zig-fmt.yml * boop * Update prettier-fmt.yml * tag * newlines * multiline * fixup * Update zig-fmt.yml * update it * fixup * both * w * Update prettier-fmt.yml * prettier all the things * Update package.json * zig fmt * ❌ ✅ * bump * . * quotes * fix prettier ignore * once more * Update prettier-fmt.yml * Update fallback.ts * consistentcy --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
33 lines
977 B
JavaScript
33 lines
977 B
JavaScript
// This is just a no-op. Intent is to prevent importing a bunch of stuff that isn't relevant.
|
|
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 &&
|
|
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;
|
|
};
|