@whatwg-node/server
Advanced tools
Comparing version 0.4.2 to 0.4.3
53
index.js
@@ -173,8 +173,2 @@ 'use strict'; | ||
const handleRequest = typeof serverAdapterBaseObject === 'function' ? serverAdapterBaseObject : serverAdapterBaseObject.handle; | ||
function fetchFn(input, init, ...ctx) { | ||
if (typeof input === 'string' || input instanceof URL) { | ||
return handleRequest(new RequestCtor(input, init), Object.assign({}, ...ctx)); | ||
} | ||
return handleRequest(input, Object.assign({}, init, ...ctx)); | ||
} | ||
function handleNodeRequest(nodeRequest, serverContext) { | ||
@@ -213,23 +207,8 @@ const request = normalizeNodeRequest(nodeRequest, RequestCtor); | ||
} | ||
function genericRequestHandler(input, ctx = {}, ...rest) { | ||
function handleRequestWithWaitUntil(request, ctx, ...rest) { | ||
var _a; | ||
if ('process' in globalThis && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a['bun']) != null) { | ||
// This is required for bun | ||
input.text(); | ||
request.text(); | ||
} | ||
// If it is a Node request | ||
if (isReadable(input) && ctx != null && isServerResponse(ctx)) { | ||
return requestListener(input, ctx); | ||
} | ||
// Is input a container object over Request? | ||
if (input.request) { | ||
// Is it FetchEvent? | ||
if (input.respondWith) { | ||
return handleEvent(input); | ||
} | ||
// In this input is also the context | ||
return handleRequest(input.request, input); | ||
} | ||
// Or is it Request itself? | ||
// Then ctx is present and it is the context | ||
if ((rest === null || rest === void 0 ? void 0 : rest.length) > 0) { | ||
@@ -243,3 +222,3 @@ ctx = Object.assign({}, ctx, ...rest); | ||
}; | ||
const response$ = handleRequest(input, { | ||
const response$ = handleRequest(request, { | ||
...ctx, | ||
@@ -254,4 +233,28 @@ waitUntil(p) { | ||
} | ||
return handleRequest(input, ctx); | ||
return handleRequest(request, ctx); | ||
} | ||
function genericRequestHandler(input, ctx = {}, ...rest) { | ||
// If it is a Node request | ||
if (isReadable(input) && ctx != null && isServerResponse(ctx)) { | ||
return requestListener(input, ctx); | ||
} | ||
// Is input a container object over Request? | ||
if (input.request) { | ||
// Is it FetchEvent? | ||
if (input.respondWith) { | ||
return handleEvent(input); | ||
} | ||
// In this input is also the context | ||
return handleRequestWithWaitUntil(input.request, input, ...rest); | ||
} | ||
// Or is it Request itself? | ||
// Then ctx is present and it is the context | ||
return handleRequestWithWaitUntil(input, ctx, ...rest); | ||
} | ||
function fetchFn(input, init, ...ctx) { | ||
if (typeof input === 'string' || input instanceof URL) { | ||
return handleRequestWithWaitUntil(new RequestCtor(input, init), Object.assign({}, ...ctx)); | ||
} | ||
return handleRequestWithWaitUntil(input, Object.assign({}, init, ...ctx)); | ||
} | ||
const adapterObj = { | ||
@@ -258,0 +261,0 @@ handleRequest, |
{ | ||
"name": "@whatwg-node/server", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "Fetch API compliant HTTP Server adapter", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -195,2 +195,18 @@ # WHATWG Node Generic Server Adapter | ||
### Bun | ||
[Bun](https://bun.sh/) is a modern JavaScript runtime like Node or Deno, and it supports Fetch API as a first class citizen. | ||
So the configuration is really simple like any other JS runtime; | ||
```ts | ||
import myServerAdapter from './myServerAdapter' | ||
Bun.serve(myServerAdapter) | ||
const server = Bun.serve(yoga) | ||
console.info( | ||
`Server is running on ${server.hostname}`, | ||
) | ||
``` | ||
## File Uploads / Multipart Requests | ||
@@ -197,0 +213,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38197
663
306