@whatwg-node/server
Advanced tools
Comparing version 0.4.18-alpha-20221220105110-a226647 to 0.4.18-alpha-20221220120052-cd1457c
@@ -12,7 +12,7 @@ /// <reference types="node" /> | ||
} | ||
export interface ServerAdapterObject<TServerContext> extends EventListenerObject { | ||
export interface ServerAdapterObject<TServerContext, TBaseObject extends ServerAdapterBaseObject<TServerContext, ServerAdapterRequestHandler<TServerContext>>> extends EventListenerObject { | ||
/** | ||
* A basic request listener that takes a `Request` with the server context and returns a `Response`. | ||
*/ | ||
handleRequest: (request: Request, ctx: TServerContext) => Promise<Response> | Response; | ||
handleRequest: TBaseObject['handle']; | ||
/** | ||
@@ -46,3 +46,3 @@ * WHATWG Fetch spec compliant `fetch` function that can be used for testing purposes. | ||
} | ||
export type ServerAdapter<TServerContext, TBaseObject extends ServerAdapterBaseObject<TServerContext>> = TBaseObject & ServerAdapterObject<TServerContext>['handle'] & ServerAdapterObject<TServerContext>; | ||
export type ServerAdapter<TServerContext, TBaseObject extends ServerAdapterBaseObject<TServerContext>> = TBaseObject & ServerAdapterObject<TServerContext, TBaseObject>['handle'] & ServerAdapterObject<TServerContext, TBaseObject>; | ||
export type ServerAdapterRequestHandler<TServerContext> = (request: Request, ctx: TServerContext) => Promise<Response> | Response; | ||
@@ -49,0 +49,0 @@ export type DefaultServerAdapterContext = { |
13
index.js
@@ -194,14 +194,3 @@ 'use strict'; | ||
RequestCtor = fetch.Request) { | ||
const providedRequestHandler = typeof serverAdapterBaseObject === 'function' ? serverAdapterBaseObject : serverAdapterBaseObject.handle; | ||
async function handleRequest(request, ctx) { | ||
try { | ||
return await providedRequestHandler(request, ctx); | ||
} | ||
catch (e) { | ||
return new Response(e.stack || e.message || e.toString(), { | ||
status: e.statusCode || e.status || 500, | ||
statusText: e.statusText || 'Internal Server Error', | ||
}); | ||
} | ||
} | ||
const handleRequest = typeof serverAdapterBaseObject === 'function' ? serverAdapterBaseObject : serverAdapterBaseObject.handle; | ||
function handleNodeRequest(nodeRequest, ...ctx) { | ||
@@ -208,0 +197,0 @@ const serverContext = ctx.length > 1 ? Object.assign({}, ...ctx) : ctx[0]; |
{ | ||
"name": "@whatwg-node/server", | ||
"version": "0.4.18-alpha-20221220105110-a226647", | ||
"version": "0.4.18-alpha-20221220120052-cd1457c", | ||
"description": "Fetch API compliant HTTP Server adapter", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
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
41737
734