@whatwg-node/server
Advanced tools
Comparing version 0.4.6-alpha-20220921172951-5c43d9d to 0.4.6-alpha-20220922124249-c941ae6
/// <reference types="node" /> | ||
/// <reference lib="webworker" /> | ||
import type { RequestListener, ServerResponse } from 'node:http'; | ||
import type { IncomingMessage, ServerResponse } from 'node:http'; | ||
import { NodeRequest } from './utils'; | ||
@@ -37,3 +37,4 @@ export interface ServerAdapterBaseObject<TServerContext, THandleRequest extends ServerAdapterRequestHandler<TServerContext> = ServerAdapterRequestHandler<TServerContext>> { | ||
*/ | ||
requestListener: RequestListener; | ||
requestListener(req: IncomingMessage, res: ServerResponse, ctx: TServerContext): void; | ||
requestListener(req: IncomingMessage, res: ServerResponse, ...ctx: Partial<TServerContext>[]): void; | ||
/** | ||
@@ -40,0 +41,0 @@ * Proxy to requestListener to mimic Node middlewares |
@@ -194,5 +194,10 @@ 'use strict'; | ||
} | ||
async function requestListener(nodeRequest, serverResponse) { | ||
async function requestListener(nodeRequest, serverResponse, ...ctx) { | ||
const waitUntilPromises = []; | ||
let serverContext = {}; | ||
if ((ctx === null || ctx === void 0 ? void 0 : ctx.length) > 0) { | ||
serverContext = Object.assign({}, serverContext, ...ctx); | ||
} | ||
const response = await handleNodeRequest(nodeRequest, { | ||
...serverContext, | ||
req: nodeRequest, | ||
@@ -276,3 +281,3 @@ res: serverResponse, | ||
if (isReadable(input) && isServerResponse(initOrCtxOrRes)) { | ||
return requestListener(input, initOrCtxOrRes); | ||
return requestListener(input, initOrCtxOrRes, ...ctx); | ||
} | ||
@@ -279,0 +284,0 @@ if (isServerResponse(initOrCtxOrRes)) { |
{ | ||
"name": "@whatwg-node/server", | ||
"version": "0.4.6-alpha-20220921172951-5c43d9d", | ||
"version": "0.4.6-alpha-20220922124249-c941ae6", | ||
"description": "Fetch API compliant HTTP Server adapter", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -120,3 +120,6 @@ # WHATWG Node Generic Server Adapter | ||
handler: async (req, reply) => { | ||
const response = await myServerAdapter.handleNodeRequest(req) | ||
const response = await myServerAdapter.handleNodeRequest(req, { | ||
req, | ||
reply, | ||
}) | ||
response.headers.forEach((value, key) => { | ||
@@ -123,0 +126,0 @@ reply.header(key, value) |
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
42327
763
308