@hono/node-server
Advanced tools
Comparing version 1.9.1 to 1.10.0
@@ -58,5 +58,2 @@ "use strict"; | ||
}; | ||
Object.defineProperty(global, "Request", { | ||
value: Request | ||
}); | ||
var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -267,5 +264,2 @@ const headerRecord = []; | ||
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype); | ||
Object.defineProperty(global, "Response", { | ||
value: Response2 | ||
}); | ||
var stateKey = Reflect.ownKeys(new GlobalResponse()).find( | ||
@@ -397,2 +391,10 @@ (k) => typeof k === "symbol" && k.toString() === "Symbol(state)" | ||
var getRequestListener = (fetchCallback, options = {}) => { | ||
if (options.overrideGlobalObjects !== false && global.Request !== Request) { | ||
Object.defineProperty(global, "Request", { | ||
value: Request | ||
}); | ||
Object.defineProperty(global, "Response", { | ||
value: Response2 | ||
}); | ||
} | ||
return async (incoming, outgoing) => { | ||
@@ -436,3 +438,5 @@ let res; | ||
const fetchCallback = options.fetch; | ||
const requestListener = getRequestListener(fetchCallback); | ||
const requestListener = getRequestListener(fetchCallback, { | ||
overrideGlobalObjects: options.overrideGlobalObjects | ||
}); | ||
const createServer = options.createServer || import_node_http.createServer; | ||
@@ -439,0 +443,0 @@ const server = createServer(options.serverOptions || {}, requestListener); |
@@ -8,4 +8,5 @@ import { IncomingMessage, ServerResponse } from 'node:http'; | ||
errorHandler?: CustomErrorHandler; | ||
overrideGlobalObjects?: boolean; | ||
}) => (incoming: IncomingMessage | Http2ServerRequest, outgoing: ServerResponse | Http2ServerResponse) => Promise<void>; | ||
export { getRequestListener }; |
@@ -53,5 +53,2 @@ "use strict"; | ||
}; | ||
Object.defineProperty(global, "Request", { | ||
value: Request | ||
}); | ||
var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -262,5 +259,2 @@ const headerRecord = []; | ||
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype); | ||
Object.defineProperty(global, "Response", { | ||
value: Response2 | ||
}); | ||
var stateKey = Reflect.ownKeys(new GlobalResponse()).find( | ||
@@ -392,2 +386,10 @@ (k) => typeof k === "symbol" && k.toString() === "Symbol(state)" | ||
var getRequestListener = (fetchCallback, options = {}) => { | ||
if (options.overrideGlobalObjects !== false && global.Request !== Request) { | ||
Object.defineProperty(global, "Request", { | ||
value: Request | ||
}); | ||
Object.defineProperty(global, "Response", { | ||
value: Response2 | ||
}); | ||
} | ||
return async (incoming, outgoing) => { | ||
@@ -394,0 +396,0 @@ let res; |
@@ -44,5 +44,2 @@ "use strict"; | ||
}; | ||
Object.defineProperty(global, "Request", { | ||
value: Request | ||
}); | ||
var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -49,0 +46,0 @@ const headerRecord = []; |
@@ -111,5 +111,2 @@ "use strict"; | ||
Object.setPrototypeOf(Response.prototype, GlobalResponse.prototype); | ||
Object.defineProperty(global, "Response", { | ||
value: Response | ||
}); | ||
var stateKey = Reflect.ownKeys(new GlobalResponse()).find( | ||
@@ -116,0 +113,0 @@ (k) => typeof k === "symbol" && k.toString() === "Symbol(state)" |
@@ -55,5 +55,2 @@ "use strict"; | ||
}; | ||
Object.defineProperty(global, "Request", { | ||
value: Request | ||
}); | ||
var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -264,5 +261,2 @@ const headerRecord = []; | ||
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype); | ||
Object.defineProperty(global, "Response", { | ||
value: Response2 | ||
}); | ||
var stateKey = Reflect.ownKeys(new GlobalResponse()).find( | ||
@@ -394,2 +388,10 @@ (k) => typeof k === "symbol" && k.toString() === "Symbol(state)" | ||
var getRequestListener = (fetchCallback, options = {}) => { | ||
if (options.overrideGlobalObjects !== false && global.Request !== Request) { | ||
Object.defineProperty(global, "Request", { | ||
value: Request | ||
}); | ||
Object.defineProperty(global, "Response", { | ||
value: Response2 | ||
}); | ||
} | ||
return async (incoming, outgoing) => { | ||
@@ -433,3 +435,5 @@ let res; | ||
const fetchCallback = options.fetch; | ||
const requestListener = getRequestListener(fetchCallback); | ||
const requestListener = getRequestListener(fetchCallback, { | ||
overrideGlobalObjects: options.overrideGlobalObjects | ||
}); | ||
const createServer = options.createServer || import_node_http.createServer; | ||
@@ -436,0 +440,0 @@ const server = createServer(options.serverOptions || {}, requestListener); |
@@ -37,2 +37,3 @@ import { IncomingMessage, ServerResponse, Server, ServerOptions as ServerOptions$1, createServer } from 'node:http'; | ||
fetch: FetchCallback; | ||
overrideGlobalObjects?: boolean; | ||
port?: number; | ||
@@ -39,0 +40,0 @@ hostname?: string; |
@@ -53,5 +53,2 @@ "use strict"; | ||
}; | ||
Object.defineProperty(global, "Request", { | ||
value: Request | ||
}); | ||
var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -262,5 +259,2 @@ const headerRecord = []; | ||
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype); | ||
Object.defineProperty(global, "Response", { | ||
value: Response2 | ||
}); | ||
var stateKey = Reflect.ownKeys(new GlobalResponse()).find( | ||
@@ -392,2 +386,10 @@ (k) => typeof k === "symbol" && k.toString() === "Symbol(state)" | ||
var getRequestListener = (fetchCallback, options = {}) => { | ||
if (options.overrideGlobalObjects !== false && global.Request !== Request) { | ||
Object.defineProperty(global, "Request", { | ||
value: Request | ||
}); | ||
Object.defineProperty(global, "Response", { | ||
value: Response2 | ||
}); | ||
} | ||
return async (incoming, outgoing) => { | ||
@@ -394,0 +396,0 @@ let res; |
{ | ||
"name": "@hono/node-server", | ||
"version": "1.9.1", | ||
"version": "1.10.0", | ||
"description": "Node.js Adapter for Hono", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -51,5 +51,5 @@ # Node.js Adapter for Hono | ||
You can install from npm registry with `npm` command: | ||
You can install it from the npm registry with `npm` command: | ||
``` | ||
```sh | ||
npm install @hono/node-server | ||
@@ -60,3 +60,3 @@ ``` | ||
``` | ||
```sh | ||
yarn add @hono/node-server | ||
@@ -84,3 +84,3 @@ ``` | ||
``` | ||
```sh | ||
ts-node ./index.ts | ||
@@ -120,2 +120,13 @@ ``` | ||
### `overrideGlobalObjects` | ||
The default value is `true`. The Node.js Adapter rewrites the global Request/Response and uses a lightweight Request/Response to improve performance. If you don't want to do that, set `false`. | ||
```ts | ||
serve({ | ||
fetch: app.fetch, | ||
overrideGlobalObjects: false, | ||
}) | ||
``` | ||
## Middleware | ||
@@ -122,0 +133,0 @@ |
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
151007
4571
265