@hono/node-server
Advanced tools
Comparing version 1.10.1 to 1.11.0
export { createAdaptorServer, serve } from './server.js'; | ||
export { getRequestListener } from './listener.js'; | ||
export { RequestError } from './request.js'; | ||
export { Http2Bindings, HttpBindings } from './types.js'; | ||
@@ -4,0 +5,0 @@ import 'node:net'; |
@@ -33,2 +33,3 @@ "use strict"; | ||
__export(src_exports, { | ||
RequestError: () => RequestError, | ||
createAdaptorServer: () => createAdaptorServer, | ||
@@ -46,2 +47,14 @@ getRequestListener: () => getRequestListener, | ||
var import_node_stream = require("stream"); | ||
var RequestError = class extends Error { | ||
static name = "RequestError"; | ||
constructor(message, options) { | ||
super(message, options); | ||
} | ||
}; | ||
var toRequestError = (e) => { | ||
if (e instanceof RequestError) { | ||
return e; | ||
} | ||
return new RequestError(e.message, { cause: e }); | ||
}; | ||
var GlobalRequest = global.Request; | ||
@@ -136,8 +149,16 @@ var Request = class extends GlobalRequest { | ||
Object.setPrototypeOf(requestPrototype, Request.prototype); | ||
var newRequest = (incoming) => { | ||
var newRequest = (incoming, defaultHostname) => { | ||
const req = Object.create(requestPrototype); | ||
req[incomingKey] = incoming; | ||
req[urlKey] = new URL( | ||
`${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host}${incoming.url}` | ||
).href; | ||
const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname; | ||
if (!host) { | ||
throw new RequestError("Missing host header"); | ||
} | ||
const url = new URL( | ||
`${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}` | ||
); | ||
if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) { | ||
throw new RequestError("Invalid host header"); | ||
} | ||
req[urlKey] = url.href; | ||
return req; | ||
@@ -305,2 +326,5 @@ }; | ||
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i; | ||
var handleRequestError = () => new Response(null, { | ||
status: 400 | ||
}); | ||
var handleFetchError = (e) => new Response(null, { | ||
@@ -402,5 +426,5 @@ status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500 | ||
return async (incoming, outgoing) => { | ||
let res; | ||
let res, req; | ||
try { | ||
const req = newRequest(incoming); | ||
req = newRequest(incoming, options.hostname); | ||
outgoing.on("close", () => { | ||
@@ -418,6 +442,8 @@ if (incoming.destroyed) { | ||
if (options.errorHandler) { | ||
res = await options.errorHandler(e); | ||
res = await options.errorHandler(req ? e : toRequestError(e)); | ||
if (!res) { | ||
return; | ||
} | ||
} else if (!req) { | ||
res = handleRequestError(); | ||
} else { | ||
@@ -442,2 +468,3 @@ res = handleFetchError(e); | ||
const requestListener = getRequestListener(fetchCallback, { | ||
hostname: options.hostname, | ||
overrideGlobalObjects: options.overrideGlobalObjects | ||
@@ -459,2 +486,3 @@ }); | ||
0 && (module.exports = { | ||
RequestError, | ||
createAdaptorServer, | ||
@@ -461,0 +489,0 @@ getRequestListener, |
@@ -7,2 +7,3 @@ import { IncomingMessage, ServerResponse } from 'node:http'; | ||
declare const getRequestListener: (fetchCallback: FetchCallback, options?: { | ||
hostname?: string; | ||
errorHandler?: CustomErrorHandler; | ||
@@ -9,0 +10,0 @@ overrideGlobalObjects?: boolean; |
@@ -40,2 +40,14 @@ "use strict"; | ||
var import_node_stream = require("stream"); | ||
var RequestError = class extends Error { | ||
static name = "RequestError"; | ||
constructor(message, options) { | ||
super(message, options); | ||
} | ||
}; | ||
var toRequestError = (e) => { | ||
if (e instanceof RequestError) { | ||
return e; | ||
} | ||
return new RequestError(e.message, { cause: e }); | ||
}; | ||
var GlobalRequest = global.Request; | ||
@@ -130,8 +142,16 @@ var Request = class extends GlobalRequest { | ||
Object.setPrototypeOf(requestPrototype, Request.prototype); | ||
var newRequest = (incoming) => { | ||
var newRequest = (incoming, defaultHostname) => { | ||
const req = Object.create(requestPrototype); | ||
req[incomingKey] = incoming; | ||
req[urlKey] = new URL( | ||
`${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host}${incoming.url}` | ||
).href; | ||
const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname; | ||
if (!host) { | ||
throw new RequestError("Missing host header"); | ||
} | ||
const url = new URL( | ||
`${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}` | ||
); | ||
if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) { | ||
throw new RequestError("Invalid host header"); | ||
} | ||
req[urlKey] = url.href; | ||
return req; | ||
@@ -299,2 +319,5 @@ }; | ||
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i; | ||
var handleRequestError = () => new Response(null, { | ||
status: 400 | ||
}); | ||
var handleFetchError = (e) => new Response(null, { | ||
@@ -396,5 +419,5 @@ status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500 | ||
return async (incoming, outgoing) => { | ||
let res; | ||
let res, req; | ||
try { | ||
const req = newRequest(incoming); | ||
req = newRequest(incoming, options.hostname); | ||
outgoing.on("close", () => { | ||
@@ -412,6 +435,8 @@ if (incoming.destroyed) { | ||
if (options.errorHandler) { | ||
res = await options.errorHandler(e); | ||
res = await options.errorHandler(req ? e : toRequestError(e)); | ||
if (!res) { | ||
return; | ||
} | ||
} else if (!req) { | ||
res = handleRequestError(); | ||
} else { | ||
@@ -418,0 +443,0 @@ res = handleFetchError(e); |
import { IncomingMessage } from 'node:http'; | ||
import { Http2ServerRequest } from 'node:http2'; | ||
declare class RequestError extends Error { | ||
static name: string; | ||
constructor(message: string, options?: { | ||
cause?: unknown; | ||
}); | ||
} | ||
declare const toRequestError: (e: unknown) => RequestError; | ||
declare const GlobalRequest: { | ||
@@ -12,4 +19,4 @@ new (input: RequestInfo | URL, init?: RequestInit | undefined): globalThis.Request; | ||
declare const getAbortController: unique symbol; | ||
declare const newRequest: (incoming: IncomingMessage | Http2ServerRequest) => any; | ||
declare const newRequest: (incoming: IncomingMessage | Http2ServerRequest, defaultHostname?: string) => any; | ||
export { GlobalRequest, Request, getAbortController, newRequest }; | ||
export { GlobalRequest, Request, RequestError, getAbortController, newRequest, toRequestError }; |
@@ -25,4 +25,6 @@ "use strict"; | ||
Request: () => Request, | ||
RequestError: () => RequestError, | ||
getAbortController: () => getAbortController, | ||
newRequest: () => newRequest | ||
newRequest: () => newRequest, | ||
toRequestError: () => toRequestError | ||
}); | ||
@@ -32,2 +34,14 @@ module.exports = __toCommonJS(request_exports); | ||
var import_node_stream = require("stream"); | ||
var RequestError = class extends Error { | ||
static name = "RequestError"; | ||
constructor(message, options) { | ||
super(message, options); | ||
} | ||
}; | ||
var toRequestError = (e) => { | ||
if (e instanceof RequestError) { | ||
return e; | ||
} | ||
return new RequestError(e.message, { cause: e }); | ||
}; | ||
var GlobalRequest = global.Request; | ||
@@ -122,8 +136,16 @@ var Request = class extends GlobalRequest { | ||
Object.setPrototypeOf(requestPrototype, Request.prototype); | ||
var newRequest = (incoming) => { | ||
var newRequest = (incoming, defaultHostname) => { | ||
const req = Object.create(requestPrototype); | ||
req[incomingKey] = incoming; | ||
req[urlKey] = new URL( | ||
`${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host}${incoming.url}` | ||
).href; | ||
const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname; | ||
if (!host) { | ||
throw new RequestError("Missing host header"); | ||
} | ||
const url = new URL( | ||
`${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}` | ||
); | ||
if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) { | ||
throw new RequestError("Invalid host header"); | ||
} | ||
req[urlKey] = url.href; | ||
return req; | ||
@@ -135,4 +157,6 @@ }; | ||
Request, | ||
RequestError, | ||
getAbortController, | ||
newRequest | ||
newRequest, | ||
toRequestError | ||
}); |
@@ -42,2 +42,14 @@ "use strict"; | ||
var import_node_stream = require("stream"); | ||
var RequestError = class extends Error { | ||
static name = "RequestError"; | ||
constructor(message, options) { | ||
super(message, options); | ||
} | ||
}; | ||
var toRequestError = (e) => { | ||
if (e instanceof RequestError) { | ||
return e; | ||
} | ||
return new RequestError(e.message, { cause: e }); | ||
}; | ||
var GlobalRequest = global.Request; | ||
@@ -132,8 +144,16 @@ var Request = class extends GlobalRequest { | ||
Object.setPrototypeOf(requestPrototype, Request.prototype); | ||
var newRequest = (incoming) => { | ||
var newRequest = (incoming, defaultHostname) => { | ||
const req = Object.create(requestPrototype); | ||
req[incomingKey] = incoming; | ||
req[urlKey] = new URL( | ||
`${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host}${incoming.url}` | ||
).href; | ||
const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname; | ||
if (!host) { | ||
throw new RequestError("Missing host header"); | ||
} | ||
const url = new URL( | ||
`${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}` | ||
); | ||
if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) { | ||
throw new RequestError("Invalid host header"); | ||
} | ||
req[urlKey] = url.href; | ||
return req; | ||
@@ -301,2 +321,5 @@ }; | ||
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i; | ||
var handleRequestError = () => new Response(null, { | ||
status: 400 | ||
}); | ||
var handleFetchError = (e) => new Response(null, { | ||
@@ -398,5 +421,5 @@ status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500 | ||
return async (incoming, outgoing) => { | ||
let res; | ||
let res, req; | ||
try { | ||
const req = newRequest(incoming); | ||
req = newRequest(incoming, options.hostname); | ||
outgoing.on("close", () => { | ||
@@ -414,6 +437,8 @@ if (incoming.destroyed) { | ||
if (options.errorHandler) { | ||
res = await options.errorHandler(e); | ||
res = await options.errorHandler(req ? e : toRequestError(e)); | ||
if (!res) { | ||
return; | ||
} | ||
} else if (!req) { | ||
res = handleRequestError(); | ||
} else { | ||
@@ -438,2 +463,3 @@ res = handleFetchError(e); | ||
const requestListener = getRequestListener(fetchCallback, { | ||
hostname: options.hostname, | ||
overrideGlobalObjects: options.overrideGlobalObjects | ||
@@ -440,0 +466,0 @@ }); |
@@ -40,2 +40,14 @@ "use strict"; | ||
var import_node_stream = require("stream"); | ||
var RequestError = class extends Error { | ||
static name = "RequestError"; | ||
constructor(message, options) { | ||
super(message, options); | ||
} | ||
}; | ||
var toRequestError = (e) => { | ||
if (e instanceof RequestError) { | ||
return e; | ||
} | ||
return new RequestError(e.message, { cause: e }); | ||
}; | ||
var GlobalRequest = global.Request; | ||
@@ -130,8 +142,16 @@ var Request = class extends GlobalRequest { | ||
Object.setPrototypeOf(requestPrototype, Request.prototype); | ||
var newRequest = (incoming) => { | ||
var newRequest = (incoming, defaultHostname) => { | ||
const req = Object.create(requestPrototype); | ||
req[incomingKey] = incoming; | ||
req[urlKey] = new URL( | ||
`${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host}${incoming.url}` | ||
).href; | ||
const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname; | ||
if (!host) { | ||
throw new RequestError("Missing host header"); | ||
} | ||
const url = new URL( | ||
`${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}` | ||
); | ||
if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) { | ||
throw new RequestError("Invalid host header"); | ||
} | ||
req[urlKey] = url.href; | ||
return req; | ||
@@ -299,2 +319,5 @@ }; | ||
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i; | ||
var handleRequestError = () => new Response(null, { | ||
status: 400 | ||
}); | ||
var handleFetchError = (e) => new Response(null, { | ||
@@ -396,5 +419,5 @@ status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500 | ||
return async (incoming, outgoing) => { | ||
let res; | ||
let res, req; | ||
try { | ||
const req = newRequest(incoming); | ||
req = newRequest(incoming, options.hostname); | ||
outgoing.on("close", () => { | ||
@@ -412,6 +435,8 @@ if (incoming.destroyed) { | ||
if (options.errorHandler) { | ||
res = await options.errorHandler(e); | ||
res = await options.errorHandler(req ? e : toRequestError(e)); | ||
if (!res) { | ||
return; | ||
} | ||
} else if (!req) { | ||
res = handleRequestError(); | ||
} else { | ||
@@ -418,0 +443,0 @@ res = handleFetchError(e); |
{ | ||
"name": "@hono/node-server", | ||
"version": "1.10.1", | ||
"version": "1.11.0", | ||
"description": "Node.js Adapter for Hono", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
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
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
159282
4833