@whatwg-node/server 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/index.js +28 -25
- package/index.mjs +28 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -192,6 +192,22 @@ import myServerAdapter from './myServerAdapter'
|
|
|
192
192
|
export { myServerAdapter as get, myServerAdapter as post }
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
+
### Bun
|
|
196
|
+
|
|
197
|
+
[Bun](https://bun.sh/) is a modern JavaScript runtime like Node or Deno, and it supports Fetch API as a first class citizen.
|
|
198
|
+
So the configuration is really simple like any other JS runtime;
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
import myServerAdapter from './myServerAdapter'
|
|
202
|
+
|
|
203
|
+
Bun.serve(myServerAdapter)
|
|
204
|
+
|
|
205
|
+
const server = Bun.serve(yoga)
|
|
206
|
+
console.info(
|
|
207
|
+
`Server is running on ${server.hostname}`,
|
|
208
|
+
)
|
|
209
|
+
```
|
|
210
|
+
|
|
195
211
|
## File Uploads / Multipart Requests
|
|
196
212
|
|
|
197
213
|
Multipart requests are a type of HTTP request that allows you to send blobs together with regular text data which has a mime-type `multipart/form-data`.
|
package/index.js
CHANGED
|
@@ -170,12 +170,6 @@ function createServerAdapter(serverAdapterBaseObject,
|
|
|
170
170
|
*/
|
|
171
171
|
RequestCtor = fetch.Request) {
|
|
172
172
|
const handleRequest = typeof serverAdapterBaseObject === 'function' ? serverAdapterBaseObject : serverAdapterBaseObject.handle;
|
|
173
|
-
function fetchFn(input, init, ...ctx) {
|
|
174
|
-
if (typeof input === 'string' || input instanceof URL) {
|
|
175
|
-
return handleRequest(new RequestCtor(input, init), Object.assign({}, ...ctx));
|
|
176
|
-
}
|
|
177
|
-
return handleRequest(input, Object.assign({}, init, ...ctx));
|
|
178
|
-
}
|
|
179
173
|
function handleNodeRequest(nodeRequest, serverContext) {
|
|
180
174
|
const request = normalizeNodeRequest(nodeRequest, RequestCtor);
|
|
181
175
|
return handleRequest(request, serverContext);
|
|
@@ -209,27 +203,12 @@ RequestCtor = fetch.Request) {
|
|
|
209
203
|
const response$ = handleRequest(event.request, event);
|
|
210
204
|
event.respondWith(response$);
|
|
211
205
|
}
|
|
212
|
-
function
|
|
206
|
+
function handleRequestWithWaitUntil(request, ctx, ...rest) {
|
|
213
207
|
var _a;
|
|
214
208
|
if ('process' in globalThis && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a['bun']) != null) {
|
|
215
209
|
// This is required for bun
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
// If it is a Node request
|
|
219
|
-
if (isReadable(input) && ctx != null && isServerResponse(ctx)) {
|
|
220
|
-
return requestListener(input, ctx);
|
|
210
|
+
request.text();
|
|
221
211
|
}
|
|
222
|
-
// Is input a container object over Request?
|
|
223
|
-
if (input.request) {
|
|
224
|
-
// Is it FetchEvent?
|
|
225
|
-
if (input.respondWith) {
|
|
226
|
-
return handleEvent(input);
|
|
227
|
-
}
|
|
228
|
-
// In this input is also the context
|
|
229
|
-
return handleRequest(input.request, input);
|
|
230
|
-
}
|
|
231
|
-
// Or is it Request itself?
|
|
232
|
-
// Then ctx is present and it is the context
|
|
233
212
|
if ((rest === null || rest === void 0 ? void 0 : rest.length) > 0) {
|
|
234
213
|
ctx = Object.assign({}, ctx, ...rest);
|
|
235
214
|
}
|
|
@@ -238,7 +217,7 @@ RequestCtor = fetch.Request) {
|
|
|
238
217
|
ctx.waitUntil = (p) => {
|
|
239
218
|
waitUntilPromises.push(p);
|
|
240
219
|
};
|
|
241
|
-
const response$ = handleRequest(
|
|
220
|
+
const response$ = handleRequest(request, {
|
|
242
221
|
...ctx,
|
|
243
222
|
waitUntil(p) {
|
|
244
223
|
waitUntilPromises.push(p);
|
|
@@ -248,7 +227,31 @@ RequestCtor = fetch.Request) {
|
|
|
248
227
|
return handleWaitUntils(waitUntilPromises).then(() => response$);
|
|
249
228
|
}
|
|
250
229
|
}
|
|
251
|
-
return handleRequest(
|
|
230
|
+
return handleRequest(request, ctx);
|
|
231
|
+
}
|
|
232
|
+
function genericRequestHandler(input, ctx = {}, ...rest) {
|
|
233
|
+
// If it is a Node request
|
|
234
|
+
if (isReadable(input) && ctx != null && isServerResponse(ctx)) {
|
|
235
|
+
return requestListener(input, ctx);
|
|
236
|
+
}
|
|
237
|
+
// Is input a container object over Request?
|
|
238
|
+
if (input.request) {
|
|
239
|
+
// Is it FetchEvent?
|
|
240
|
+
if (input.respondWith) {
|
|
241
|
+
return handleEvent(input);
|
|
242
|
+
}
|
|
243
|
+
// In this input is also the context
|
|
244
|
+
return handleRequestWithWaitUntil(input.request, input, ...rest);
|
|
245
|
+
}
|
|
246
|
+
// Or is it Request itself?
|
|
247
|
+
// Then ctx is present and it is the context
|
|
248
|
+
return handleRequestWithWaitUntil(input, ctx, ...rest);
|
|
249
|
+
}
|
|
250
|
+
function fetchFn(input, init, ...ctx) {
|
|
251
|
+
if (typeof input === 'string' || input instanceof URL) {
|
|
252
|
+
return handleRequestWithWaitUntil(new RequestCtor(input, init), Object.assign({}, ...ctx));
|
|
253
|
+
}
|
|
254
|
+
return handleRequestWithWaitUntil(input, Object.assign({}, init, ...ctx));
|
|
252
255
|
}
|
|
253
256
|
const adapterObj = {
|
|
254
257
|
handleRequest,
|
package/index.mjs
CHANGED
|
@@ -166,12 +166,6 @@ function createServerAdapter(serverAdapterBaseObject,
|
|
|
166
166
|
*/
|
|
167
167
|
RequestCtor = Request) {
|
|
168
168
|
const handleRequest = typeof serverAdapterBaseObject === 'function' ? serverAdapterBaseObject : serverAdapterBaseObject.handle;
|
|
169
|
-
function fetchFn(input, init, ...ctx) {
|
|
170
|
-
if (typeof input === 'string' || input instanceof URL) {
|
|
171
|
-
return handleRequest(new RequestCtor(input, init), Object.assign({}, ...ctx));
|
|
172
|
-
}
|
|
173
|
-
return handleRequest(input, Object.assign({}, init, ...ctx));
|
|
174
|
-
}
|
|
175
169
|
function handleNodeRequest(nodeRequest, serverContext) {
|
|
176
170
|
const request = normalizeNodeRequest(nodeRequest, RequestCtor);
|
|
177
171
|
return handleRequest(request, serverContext);
|
|
@@ -205,27 +199,12 @@ RequestCtor = Request) {
|
|
|
205
199
|
const response$ = handleRequest(event.request, event);
|
|
206
200
|
event.respondWith(response$);
|
|
207
201
|
}
|
|
208
|
-
function
|
|
202
|
+
function handleRequestWithWaitUntil(request, ctx, ...rest) {
|
|
209
203
|
var _a;
|
|
210
204
|
if ('process' in globalThis && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a['bun']) != null) {
|
|
211
205
|
// This is required for bun
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
// If it is a Node request
|
|
215
|
-
if (isReadable(input) && ctx != null && isServerResponse(ctx)) {
|
|
216
|
-
return requestListener(input, ctx);
|
|
206
|
+
request.text();
|
|
217
207
|
}
|
|
218
|
-
// Is input a container object over Request?
|
|
219
|
-
if (input.request) {
|
|
220
|
-
// Is it FetchEvent?
|
|
221
|
-
if (input.respondWith) {
|
|
222
|
-
return handleEvent(input);
|
|
223
|
-
}
|
|
224
|
-
// In this input is also the context
|
|
225
|
-
return handleRequest(input.request, input);
|
|
226
|
-
}
|
|
227
|
-
// Or is it Request itself?
|
|
228
|
-
// Then ctx is present and it is the context
|
|
229
208
|
if ((rest === null || rest === void 0 ? void 0 : rest.length) > 0) {
|
|
230
209
|
ctx = Object.assign({}, ctx, ...rest);
|
|
231
210
|
}
|
|
@@ -234,7 +213,7 @@ RequestCtor = Request) {
|
|
|
234
213
|
ctx.waitUntil = (p) => {
|
|
235
214
|
waitUntilPromises.push(p);
|
|
236
215
|
};
|
|
237
|
-
const response$ = handleRequest(
|
|
216
|
+
const response$ = handleRequest(request, {
|
|
238
217
|
...ctx,
|
|
239
218
|
waitUntil(p) {
|
|
240
219
|
waitUntilPromises.push(p);
|
|
@@ -244,7 +223,31 @@ RequestCtor = Request) {
|
|
|
244
223
|
return handleWaitUntils(waitUntilPromises).then(() => response$);
|
|
245
224
|
}
|
|
246
225
|
}
|
|
247
|
-
return handleRequest(
|
|
226
|
+
return handleRequest(request, ctx);
|
|
227
|
+
}
|
|
228
|
+
function genericRequestHandler(input, ctx = {}, ...rest) {
|
|
229
|
+
// If it is a Node request
|
|
230
|
+
if (isReadable(input) && ctx != null && isServerResponse(ctx)) {
|
|
231
|
+
return requestListener(input, ctx);
|
|
232
|
+
}
|
|
233
|
+
// Is input a container object over Request?
|
|
234
|
+
if (input.request) {
|
|
235
|
+
// Is it FetchEvent?
|
|
236
|
+
if (input.respondWith) {
|
|
237
|
+
return handleEvent(input);
|
|
238
|
+
}
|
|
239
|
+
// In this input is also the context
|
|
240
|
+
return handleRequestWithWaitUntil(input.request, input, ...rest);
|
|
241
|
+
}
|
|
242
|
+
// Or is it Request itself?
|
|
243
|
+
// Then ctx is present and it is the context
|
|
244
|
+
return handleRequestWithWaitUntil(input, ctx, ...rest);
|
|
245
|
+
}
|
|
246
|
+
function fetchFn(input, init, ...ctx) {
|
|
247
|
+
if (typeof input === 'string' || input instanceof URL) {
|
|
248
|
+
return handleRequestWithWaitUntil(new RequestCtor(input, init), Object.assign({}, ...ctx));
|
|
249
|
+
}
|
|
250
|
+
return handleRequestWithWaitUntil(input, Object.assign({}, init, ...ctx));
|
|
248
251
|
}
|
|
249
252
|
const adapterObj = {
|
|
250
253
|
handleRequest,
|