@nwire/endpoint 0.10.0 → 0.10.1
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/dist/endpoint.d.ts +1 -1
- package/dist/endpoint.js +2 -2
- package/dist/lifecycle.d.ts +3 -3
- package/dist/lifecycle.js +9 -9
- package/package.json +5 -5
package/dist/endpoint.d.ts
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
* ## Why this exists
|
|
29
29
|
*
|
|
30
30
|
* Every framework eventually needs a process layer — something that knows
|
|
31
|
-
* about SIGTERM, drains in-flight requests, exposes `/
|
|
31
|
+
* about SIGTERM, drains in-flight requests, exposes `/live`, and binds
|
|
32
32
|
* to a port. Most frameworks bolt this on as a deployment afterthought.
|
|
33
33
|
* `@nwire/endpoint` makes it the first-class entry point so you don't
|
|
34
34
|
* write the same K8s-readiness code on every project. It works alone —
|
package/dist/endpoint.js
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
* ## Why this exists
|
|
29
29
|
*
|
|
30
30
|
* Every framework eventually needs a process layer — something that knows
|
|
31
|
-
* about SIGTERM, drains in-flight requests, exposes `/
|
|
31
|
+
* about SIGTERM, drains in-flight requests, exposes `/live`, and binds
|
|
32
32
|
* to a port. Most frameworks bolt this on as a deployment afterthought.
|
|
33
33
|
* `@nwire/endpoint` makes it the first-class entry point so you don't
|
|
34
34
|
* write the same K8s-readiness code on every project. It works alone —
|
|
@@ -405,7 +405,7 @@ function printBanner(opts) {
|
|
|
405
405
|
: ` data: (no HTTP listener)`,
|
|
406
406
|
];
|
|
407
407
|
if (opts.probePort !== undefined) {
|
|
408
|
-
// lightship's actual paths — not /
|
|
408
|
+
// lightship's actual paths — not /ready + /live (which was a
|
|
409
409
|
// historical misnaming in our docs).
|
|
410
410
|
lines.push(` probes: http://${opts.host}:${opts.probePort}/live · /ready`);
|
|
411
411
|
}
|
package/dist/lifecycle.d.ts
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
* `server.close()`. Without it, in-flight requests on persistent
|
|
8
8
|
* connections silently die when the process exits.
|
|
9
9
|
* - **lightship** — Kubernetes-style readiness/liveness probes on a
|
|
10
|
-
* separate operational port. Flips `/
|
|
10
|
+
* separate operational port. Flips `/ready` to 503 the moment shutdown
|
|
11
11
|
* starts so the load balancer stops sending new traffic — the single
|
|
12
12
|
* most important step in a zero-downtime rolling deploy.
|
|
13
13
|
*
|
|
14
14
|
* Sequence on SIGTERM/SIGINT:
|
|
15
15
|
*
|
|
16
|
-
* 1. lightship: /
|
|
16
|
+
* 1. lightship: /ready → 503 (LB removes us from rotation)
|
|
17
17
|
* 2. wait `drainDelay` (LB has time to catch up; default 10s)
|
|
18
18
|
* 3. stop accepting new connections (http-terminator)
|
|
19
19
|
* 4. drain in-flight requests (http-terminator; bounded by drainTimeout)
|
|
@@ -105,7 +105,7 @@ export interface LifecycleManager {
|
|
|
105
105
|
addCheck(check: HealthCheck): void;
|
|
106
106
|
/**
|
|
107
107
|
* Bare Node http handler for probes-on-main deployments. Mount on your
|
|
108
|
-
* own HTTP server's /
|
|
108
|
+
* own HTTP server's /live and /ready routes; the third arg picks which.
|
|
109
109
|
* No framework lock-in — works with Express, Fastify, Koa, raw http.
|
|
110
110
|
*/
|
|
111
111
|
probeHandler(req: {
|
package/dist/lifecycle.js
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
* `server.close()`. Without it, in-flight requests on persistent
|
|
8
8
|
* connections silently die when the process exits.
|
|
9
9
|
* - **lightship** — Kubernetes-style readiness/liveness probes on a
|
|
10
|
-
* separate operational port. Flips `/
|
|
10
|
+
* separate operational port. Flips `/ready` to 503 the moment shutdown
|
|
11
11
|
* starts so the load balancer stops sending new traffic — the single
|
|
12
12
|
* most important step in a zero-downtime rolling deploy.
|
|
13
13
|
*
|
|
14
14
|
* Sequence on SIGTERM/SIGINT:
|
|
15
15
|
*
|
|
16
|
-
* 1. lightship: /
|
|
16
|
+
* 1. lightship: /ready → 503 (LB removes us from rotation)
|
|
17
17
|
* 2. wait `drainDelay` (LB has time to catch up; default 10s)
|
|
18
18
|
* 3. stop accepting new connections (http-terminator)
|
|
19
19
|
* 4. drain in-flight requests (http-terminator; bounded by drainTimeout)
|
|
@@ -53,8 +53,8 @@ export async function attachLifecycle(opts) {
|
|
|
53
53
|
const healthCfg = {
|
|
54
54
|
enabled: opts.health?.enabled ?? true,
|
|
55
55
|
port: opts.health?.port ?? 9_400,
|
|
56
|
-
livenessPath: opts.health?.livenessPath ?? "/
|
|
57
|
-
readinessPath: opts.health?.readinessPath ?? "/
|
|
56
|
+
livenessPath: opts.health?.livenessPath ?? "/live",
|
|
57
|
+
readinessPath: opts.health?.readinessPath ?? "/ready",
|
|
58
58
|
checks: opts.health?.checks ?? [],
|
|
59
59
|
};
|
|
60
60
|
const terminator = createHttpTerminator({
|
|
@@ -138,9 +138,9 @@ export async function attachLifecycle(opts) {
|
|
|
138
138
|
try {
|
|
139
139
|
if (lightship) {
|
|
140
140
|
lightship.signalNotReady();
|
|
141
|
-
console.log(`[lifecycle] /
|
|
141
|
+
console.log(`[lifecycle] /ready → 503; waiting ${shutdownCfg.drainDelay}ms for LB to catch up`);
|
|
142
142
|
// The drain delay exists to give the LB time to redirect traffic
|
|
143
|
-
// after /
|
|
143
|
+
// after /ready flips to 503. Without lightship, there's no probe
|
|
144
144
|
// for an LB to poll — waiting would just stall shutdown.
|
|
145
145
|
await new Promise((r) => setTimeout(r, shutdownCfg.drainDelay));
|
|
146
146
|
}
|
|
@@ -166,13 +166,13 @@ export async function attachLifecycle(opts) {
|
|
|
166
166
|
process.once("SIGTERM", () => void shutdown("SIGTERM"));
|
|
167
167
|
process.once("SIGINT", () => void shutdown("SIGINT"));
|
|
168
168
|
/**
|
|
169
|
-
* Bare Node http handler for `/
|
|
169
|
+
* Bare Node http handler for `/live` / `/ready` on the MAIN port. Use
|
|
170
170
|
* when probes-on-main is the deployment shape (Cloud Run, Lambda Function
|
|
171
171
|
* URLs, simple K8s sidecar-free setups).
|
|
172
172
|
*
|
|
173
173
|
* const probeHandler = lifecycle.probeHandler;
|
|
174
|
-
* expressApp.get("/
|
|
175
|
-
* expressApp.get("/
|
|
174
|
+
* expressApp.get("/live", (req, res) => probeHandler(req, res, "live"));
|
|
175
|
+
* expressApp.get("/ready", (req, res) => probeHandler(req, res, "ready"));
|
|
176
176
|
*
|
|
177
177
|
* `live` is always 200 unless the process is shutting down.
|
|
178
178
|
* `ready` is 200 only when all checks pass AND we're not shutting down.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nwire/endpoint",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Nwire — production process lifecycle. Wraps any Node server (Express, Fastify, Koa, Nest, Nwire interfaces) with K8s-grade graceful shutdown, http-terminator drain, and lightship readiness/liveness probes. Standalone — no framework dependency beyond @nwire/container.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"endpoint",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"http-terminator": "^3.2.0",
|
|
34
34
|
"lightship": "^9.0.4",
|
|
35
|
-
"@nwire/
|
|
36
|
-
"@nwire/
|
|
37
|
-
"@nwire/
|
|
38
|
-
"@nwire/
|
|
35
|
+
"@nwire/hooks": "0.10.1",
|
|
36
|
+
"@nwire/container": "0.10.1",
|
|
37
|
+
"@nwire/logger": "0.10.1",
|
|
38
|
+
"@nwire/wires": "0.10.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^22.19.9",
|