@whatwg-node/server
Advanced tools
Comparing version 0.9.50 to 0.9.51-alpha-20241102144947-26086457787329511421be17d37b33c75803c54e
@@ -112,3 +112,3 @@ "use strict"; | ||
const serverContext = ctx.length > 1 ? (0, utils_js_1.completeAssign)(...ctx) : ctx[0] || {}; | ||
const request = (0, utils_js_1.normalizeNodeRequest)(nodeRequest, fetchAPI.Request); | ||
const request = (0, utils_js_1.normalizeNodeRequest)(nodeRequest, fetchAPI); | ||
return handleRequest(request, serverContext); | ||
@@ -115,0 +115,0 @@ } |
@@ -22,3 +22,2 @@ "use strict"; | ||
exports.handleResponseDecompression = handleResponseDecompression; | ||
const fetch_1 = require("@whatwg-node/fetch"); | ||
function isAsyncIterable(body) { | ||
@@ -106,7 +105,7 @@ return (body != null && typeof body === 'object' && typeof body[Symbol.asyncIterator] === 'function'); | ||
exports.nodeRequestResponseMap = new WeakMap(); | ||
function normalizeNodeRequest(nodeRequest, RequestCtor) { | ||
function normalizeNodeRequest(nodeRequest, fetchAPI) { | ||
const rawRequest = nodeRequest.raw || nodeRequest.req || nodeRequest; | ||
let fullUrl = buildFullUrl(rawRequest); | ||
if (nodeRequest.query) { | ||
const url = new fetch_1.URL(fullUrl); | ||
const url = new fetchAPI.URL(fullUrl); | ||
for (const key in nodeRequest.query) { | ||
@@ -132,3 +131,3 @@ url.searchParams.set(key, nodeRequest.query[key]); | ||
// If ponyfilled | ||
if (RequestCtor !== globalThis.Request) { | ||
if (fetchAPI.Request !== globalThis.Request) { | ||
signal = new ServerAdapterRequestAbortSignal(); | ||
@@ -155,3 +154,3 @@ sendAbortSignal = () => signal.sendAbort(); | ||
if (nodeRequest.method === 'GET' || nodeRequest.method === 'HEAD') { | ||
return new RequestCtor(fullUrl, { | ||
return new fetchAPI.Request(fullUrl, { | ||
method: nodeRequest.method, | ||
@@ -171,3 +170,3 @@ headers: normalizedHeaders, | ||
if (isRequestBody(maybeParsedBody)) { | ||
return new RequestCtor(fullUrl, { | ||
return new fetchAPI.Request(fullUrl, { | ||
method: nodeRequest.method, | ||
@@ -179,3 +178,3 @@ headers: normalizedHeaders, | ||
} | ||
const request = new RequestCtor(fullUrl, { | ||
const request = new fetchAPI.Request(fullUrl, { | ||
method: nodeRequest.method, | ||
@@ -208,3 +207,3 @@ headers: normalizedHeaders, | ||
} | ||
return new RequestCtor(fullUrl, { | ||
return new fetchAPI.Request(fullUrl, { | ||
method: nodeRequest.method, | ||
@@ -233,3 +232,3 @@ headers: normalizedHeaders, | ||
// perf: instead of spreading the object, we can just pass it as is and it performs better | ||
return new RequestCtor(fullUrl, { | ||
return new fetchAPI.Request(fullUrl, { | ||
method: nodeRequest.method, | ||
@@ -236,0 +235,0 @@ headers: normalizedHeaders, |
@@ -108,3 +108,3 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
const serverContext = ctx.length > 1 ? completeAssign(...ctx) : ctx[0] || {}; | ||
const request = normalizeNodeRequest(nodeRequest, fetchAPI.Request); | ||
const request = normalizeNodeRequest(nodeRequest, fetchAPI); | ||
return handleRequest(request, serverContext); | ||
@@ -111,0 +111,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import { URL } from '@whatwg-node/fetch'; | ||
export function isAsyncIterable(body) { | ||
@@ -83,7 +82,7 @@ return (body != null && typeof body === 'object' && typeof body[Symbol.asyncIterator] === 'function'); | ||
export const nodeRequestResponseMap = new WeakMap(); | ||
export function normalizeNodeRequest(nodeRequest, RequestCtor) { | ||
export function normalizeNodeRequest(nodeRequest, fetchAPI) { | ||
const rawRequest = nodeRequest.raw || nodeRequest.req || nodeRequest; | ||
let fullUrl = buildFullUrl(rawRequest); | ||
if (nodeRequest.query) { | ||
const url = new URL(fullUrl); | ||
const url = new fetchAPI.URL(fullUrl); | ||
for (const key in nodeRequest.query) { | ||
@@ -109,3 +108,3 @@ url.searchParams.set(key, nodeRequest.query[key]); | ||
// If ponyfilled | ||
if (RequestCtor !== globalThis.Request) { | ||
if (fetchAPI.Request !== globalThis.Request) { | ||
signal = new ServerAdapterRequestAbortSignal(); | ||
@@ -132,3 +131,3 @@ sendAbortSignal = () => signal.sendAbort(); | ||
if (nodeRequest.method === 'GET' || nodeRequest.method === 'HEAD') { | ||
return new RequestCtor(fullUrl, { | ||
return new fetchAPI.Request(fullUrl, { | ||
method: nodeRequest.method, | ||
@@ -148,3 +147,3 @@ headers: normalizedHeaders, | ||
if (isRequestBody(maybeParsedBody)) { | ||
return new RequestCtor(fullUrl, { | ||
return new fetchAPI.Request(fullUrl, { | ||
method: nodeRequest.method, | ||
@@ -156,3 +155,3 @@ headers: normalizedHeaders, | ||
} | ||
const request = new RequestCtor(fullUrl, { | ||
const request = new fetchAPI.Request(fullUrl, { | ||
method: nodeRequest.method, | ||
@@ -185,3 +184,3 @@ headers: normalizedHeaders, | ||
} | ||
return new RequestCtor(fullUrl, { | ||
return new fetchAPI.Request(fullUrl, { | ||
method: nodeRequest.method, | ||
@@ -210,3 +209,3 @@ headers: normalizedHeaders, | ||
// perf: instead of spreading the object, we can just pass it as is and it performs better | ||
return new RequestCtor(fullUrl, { | ||
return new fetchAPI.Request(fullUrl, { | ||
method: nodeRequest.method, | ||
@@ -213,0 +212,0 @@ headers: normalizedHeaders, |
{ | ||
"name": "@whatwg-node/server", | ||
"version": "0.9.50", | ||
"version": "0.9.51-alpha-20241102144947-26086457787329511421be17d37b33c75803c54e", | ||
"description": "Fetch API compliant HTTP Server adapter", | ||
"sideEffects": false, | ||
"dependencies": { | ||
"@whatwg-node/fetch": "^0.9.22", | ||
"@whatwg-node/fetch": "0.9.23-alpha-20241102144947-26086457787329511421be17d37b33c75803c54e", | ||
"tslib": "^2.6.3" | ||
@@ -9,0 +9,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
import { ServerAdapterPlugin } from './types.js'; | ||
import type { ServerAdapterPlugin } from './types.js'; | ||
export type CORSOptions = { | ||
@@ -3,0 +3,0 @@ origin?: string[] | string; |
@@ -1,2 +0,2 @@ | ||
import { ServerAdapterPlugin } from './types.js'; | ||
import type { ServerAdapterPlugin } from './types.js'; | ||
export declare function createDefaultErrorHandler<TServerContext = {}>(ResponseCtor?: typeof Response): ErrorHandler<TServerContext>; | ||
@@ -9,5 +9,5 @@ export declare class HTTPError extends Error { | ||
name: string; | ||
constructor(status: number, message: string, headers?: HeadersInit, details?: any); | ||
constructor(status: number | undefined, message: string, headers?: HeadersInit, details?: any); | ||
} | ||
export type ErrorHandler<TServerContext> = (e: any, request: Request, ctx: TServerContext) => Response | Promise<Response>; | ||
export declare function useErrorHandling<TServerContext>(onError?: ErrorHandler<TServerContext>): ServerAdapterPlugin<TServerContext>; |
@@ -34,3 +34,3 @@ import type { IncomingMessage, ServerResponse } from 'http'; | ||
export declare const nodeRequestResponseMap: WeakMap<NodeRequest, NodeResponse>; | ||
export declare function normalizeNodeRequest(nodeRequest: NodeRequest, RequestCtor: typeof Request): Request; | ||
export declare function normalizeNodeRequest(nodeRequest: NodeRequest, fetchAPI: FetchAPI): Request; | ||
export declare function isReadable(stream: any): stream is Readable; | ||
@@ -37,0 +37,0 @@ export declare function isNodeRequest(request: any): request is NodeRequest; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
149249
3172
+ Added@whatwg-node/fetch@0.9.23-alpha-20241102144947-26086457787329511421be17d37b33c75803c54e(transitive)
+ Added@whatwg-node/node-fetch@0.6.0-alpha-20241102144947-26086457787329511421be17d37b33c75803c54e(transitive)
- Removed@whatwg-node/fetch@0.9.23(transitive)
- Removed@whatwg-node/node-fetch@0.6.0(transitive)
Updated@whatwg-node/fetch@0.9.23-alpha-20241102144947-26086457787329511421be17d37b33c75803c54e