Skip to content

Commit

Permalink
Bun Support
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Sep 7, 2022
1 parent c5ff2e8 commit effc03d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/strong-penguins-begin.md
@@ -0,0 +1,6 @@
---
'@whatwg-node/fetch': minor
'@whatwg-node/server': minor
---

Bun Support
5 changes: 5 additions & 0 deletions packages/fetch/dist/create-node-ponyfill.js
Expand Up @@ -2,6 +2,11 @@ const handleFileRequest = require("./handle-file-request");

module.exports = function createNodePonyfill(opts = {}) {

// Bun already has a Fetch API
if (process.versions.bun) {
return globalThis;
}

const ponyfills = {};

if (!opts.useNodeFetch) {
Expand Down
6 changes: 5 additions & 1 deletion packages/server/src/index.ts
Expand Up @@ -49,7 +49,7 @@ export interface ServerAdapterObject<TServerContext> extends EventListenerObject
}

export type ServerAdapter<TServerContext, TBaseObject> = TBaseObject &
RequestListener &
RequestListener & ServerAdapterObject<TServerContext>['fetch'] &
ServerAdapterObject<TServerContext>;

export function createServerAdapter<
Expand Down Expand Up @@ -104,6 +104,10 @@ export function createServerAdapter<
};

function genericRequestHandler(input: any, ctx: any) {
if ('process' in globalThis && process.versions?.['bun'] != null) {
// This is required for bun
input.text();
}
// If it is a Node request
if (isReadable(input) && ctx != null && isServerResponse(ctx)) {
return requestListener(input as unknown as NodeRequest, ctx);
Expand Down

0 comments on commit effc03d

Please sign in to comment.