@askrjs/node 0.0.11 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -58,6 +58,12 @@ const server = await listen(app, {
|
|
|
58
58
|
server.close();
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
`listen()` and `serve()` apply timeout options during `http.Server` construction and configure
|
|
62
|
+
Node's incomplete-connection check interval no slower than the smallest finite request/header
|
|
63
|
+
timeout (capped at one second). This makes the authored values enforceable for stalled headers and
|
|
64
|
+
bodies instead of relying on Node's much slower default checking interval. Use explicit finite
|
|
65
|
+
`requestTimeout` and `headersTimeout` values in production; `0` retains Node's disable semantics.
|
|
66
|
+
|
|
61
67
|
Pass an `AbortSignal` to integrate shutdown with your process lifecycle.
|
|
62
68
|
|
|
63
69
|
Enable the built-in `ws` transport with `websocket: true`. It defaults to a
|
package/dist/index.d.ts
CHANGED
|
@@ -44,9 +44,9 @@ interface ListenOptions extends NodeHandlerOptions {
|
|
|
44
44
|
backlog?: number;
|
|
45
45
|
/** Aborting this signal stops the server. */
|
|
46
46
|
signal?: AbortSignal;
|
|
47
|
-
/** Node HTTP server `requestTimeout`, in milliseconds. */
|
|
47
|
+
/** Node HTTP server `requestTimeout`, enforced from server construction, in milliseconds. */
|
|
48
48
|
requestTimeout?: number;
|
|
49
|
-
/** Node HTTP server `headersTimeout`, in milliseconds. */
|
|
49
|
+
/** Node HTTP server `headersTimeout`, enforced from server construction, in milliseconds. */
|
|
50
50
|
headersTimeout?: number;
|
|
51
51
|
/** Node HTTP server `keepAliveTimeout`, in milliseconds. */
|
|
52
52
|
keepAliveTimeout?: number;
|
package/dist/index.js
CHANGED
|
@@ -327,6 +327,18 @@ function timeout(value, name) {
|
|
|
327
327
|
if (!Number.isSafeInteger(value) || value < 0) throw new TypeError(`${name} must be a non-negative safe integer.`);
|
|
328
328
|
return value;
|
|
329
329
|
}
|
|
330
|
+
function resolveServerOptions(options) {
|
|
331
|
+
const requestTimeout = timeout(options.requestTimeout, "requestTimeout");
|
|
332
|
+
const headersTimeout = timeout(options.headersTimeout, "headersTimeout");
|
|
333
|
+
const keepAliveTimeout = timeout(options.keepAliveTimeout, "keepAliveTimeout");
|
|
334
|
+
const enforced = [requestTimeout, headersTimeout].filter((value) => value !== void 0 && value > 0);
|
|
335
|
+
return {
|
|
336
|
+
requestTimeout: requestTimeout !== void 0 && headersTimeout !== void 0 && headersTimeout > requestTimeout ? headersTimeout : requestTimeout,
|
|
337
|
+
headersTimeout,
|
|
338
|
+
keepAliveTimeout,
|
|
339
|
+
connectionsCheckingInterval: enforced.length ? Math.min(1e3, ...enforced) : void 0
|
|
340
|
+
};
|
|
341
|
+
}
|
|
330
342
|
function applyServerTimeouts(server, options) {
|
|
331
343
|
const requestTimeout = timeout(options.requestTimeout, "requestTimeout");
|
|
332
344
|
const headersTimeout = timeout(options.headersTimeout, "headersTimeout");
|
|
@@ -545,7 +557,7 @@ function listen(app, options = {}) {
|
|
|
545
557
|
options.signal?.throwIfAborted();
|
|
546
558
|
const host = resolveBindHost(options);
|
|
547
559
|
const handlerOptions = handlerOptionsForHost(options, host);
|
|
548
|
-
const server = createServer(createNodeHandler(app, handlerOptions));
|
|
560
|
+
const server = createServer(resolveServerOptions(options), createNodeHandler(app, handlerOptions));
|
|
549
561
|
applyServerTimeouts(server, options);
|
|
550
562
|
const webSockets = options.websocket ? installWebSockets(server, app, options.websocket === true ? {} : options.websocket, handlerOptions) : void 0;
|
|
551
563
|
if (webSockets) {
|
|
@@ -658,7 +670,7 @@ async function serve(app, options = {}) {
|
|
|
658
670
|
}
|
|
659
671
|
return result;
|
|
660
672
|
} }, handlerOptions);
|
|
661
|
-
const server = createServer(async (request, response) => {
|
|
673
|
+
const server = createServer(resolveServerOptions(options), async (request, response) => {
|
|
662
674
|
if (!root) {
|
|
663
675
|
applicationHandler(request, response);
|
|
664
676
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@askrjs/node",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Node http adapter for @askrjs/server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"askr",
|
|
@@ -57,13 +57,13 @@
|
|
|
57
57
|
"prepublishOnly": "npm run check"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@askrjs/auth": ">=0.0
|
|
61
|
-
"@askrjs/server": ">=0.0
|
|
60
|
+
"@askrjs/auth": ">=0.2.0 <0.3.0",
|
|
61
|
+
"@askrjs/server": ">=0.2.0 <0.3.0",
|
|
62
62
|
"@types/ws": "^8.18.1",
|
|
63
63
|
"ws": "^8.21.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@askrjs/schema": ">=0.0
|
|
66
|
+
"@askrjs/schema": ">=0.2.0 <0.3.0",
|
|
67
67
|
"@types/node": "^26.2.0",
|
|
68
68
|
"publint": "^0.3.23",
|
|
69
69
|
"typescript": "^7.0.2",
|