@dokebi/web 0.4.8 → 0.4.10

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.
Files changed (3) hide show
  1. package/AI.md +3 -1
  2. package/dist/index.js +26 -4
  3. package/package.json +4 -4
package/AI.md CHANGED
@@ -10,6 +10,8 @@ npx dokebi add @dokebi/web # src/infra/web/extension.ts (the requires list
10
10
 
11
11
  > `npx dokebi` is the @dokebi/cli installed in the project (`dokebi init` adds it to devDependencies). The npm package `dokebi` is not this CLI, so never use `npx -y dokebi`. Without an installed CLI use `npx -y @dokebi/cli …`.
12
12
 
13
+ **One fastify per project (0.4.10, D-0224).** `fastify` is a peer dependency of @dokebi/web at the exact version it is built and tested on (5.12.8); every other Dokebi plugin takes it as a peer range (`^5.12.7`). npm installs one copy at the project root, so the `FastifyRequest` of web's hooks (`routeHook`, `appOf`) carries the type augmentations of session, auth and i18n (`request.session`, `request.auth`, `request.i18n`). Do not add another `fastify` version to the project's own package.json; `npm ls fastify` shows one copy. Web 0.4.9 and earlier kept their own nested copy, so the types of web's hooks missed those augmentations (TS2339 / TS2345); upgrading web removes it.
14
+
13
15
  ```yaml
14
16
  dokebi-web:
15
17
  host: 127.0.0.1 # default; 0.0.0.0 to accept outside traffic (a front proxy is recommended)
@@ -44,7 +46,7 @@ dokebi-web:
44
46
  |---|---|---|---|
45
47
  | `host` | string | `127.0.0.1` | listen address |
46
48
  | `port` | integer | 0 | 0..65535; 0 picks an ephemeral port |
47
- | `listen` | boolean | true | (0.4.8, [D-0221](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0221-process-roles.md)) `false`: open no port — a worker process started from the same code with its own dokebi.yaml (`DOKEBI_CONFIG`). Routes are still registered (`inject` answers), nothing listens, `address` stays undefined and `/health/live` and `/health/ready` are not reachable; info `Web server not listening` (`WEB_NOT_LISTENING`) once. To probe a worker over HTTP, give it a port nothing routes traffic to instead |
49
+ | `listen` | boolean | true | (0.4.8, [D-0221](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0221-process-roles.md)) `false`: open no port — a worker process started from the same code with its own dokebi.yaml (`DOKEBI_CONFIG`). Routes are still registered (`inject` answers), nothing listens, `address` stays undefined and `/health/live` and `/health/ready` are not reachable; info `Web server not listening` (`WEB_NOT_LISTENING`) once. In place of the socket the plugin holds the process open until the app drains (0.4.9: before it, a worker with no other open connection exited right after it started). `dokebi verify` skips its HTTP check for such a settings file (@dokebi/cli 0.4.45). To probe a worker over HTTP, give it a port nothing routes traffic to instead |
48
50
  | `maxBodyBytes` | integer | 1048576 | request body limit, 1 B..64 MiB |
49
51
  | `bodyLimit` | integer | — | deprecated name of `maxBodyBytes` (D-0071): warns `OPTION_DEPRECATED`; setting both is `INVALID_OPTIONS` |
50
52
  | `maxRouteBodyBytes` | integer 1..1073741824 | 67108864 | the largest `bodyLimit` one route may declare for itself (64 MiB; at least `maxBodyBytes`); a larger one fails the start with `INVALID_ROUTE` ([D-0122](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0122-studio-terminal-needs.md), below) |
package/dist/index.js CHANGED
@@ -39,6 +39,8 @@ export { errorFormat, FORM_SUBMISSION_HEADER, requestErrorFormat, SEALED_FETCH_H
39
39
  export { SEALED_LOCATION_HEADER, SEALED_PATH_HEADER, } from './seal.js';
40
40
  export { DEFAULT_DIRECTIVES, } from './security-headers.js';
41
41
  /** Set by `dokebi verify` on the app it starts (D-0065 §11); the header echoes it. */
42
+ /** The longest timer delay Node takes (about 24.8 days); the keep-alive never fires in practice. */
43
+ const KEEP_ALIVE_MS = 2 ** 31 - 1;
42
44
  const VERIFY_TOKEN_ENV = 'DOKEBI_VERIFY_TOKEN';
43
45
  const VERIFY_HEADER = 'x-dokebi-verify';
44
46
  /**
@@ -392,6 +394,12 @@ class WebOwner {
392
394
  #address;
393
395
  /** `listen: false` was logged once (D-0221). */
394
396
  #notListening = false;
397
+ /**
398
+ * D-0221: with `listen: false` this holds the process open in place of the listening socket,
399
+ * until the drain or close: a worker process with no other open handle would otherwise exit
400
+ * right after it started.
401
+ */
402
+ #keepAlive;
395
403
  #sealing;
396
404
  /** D-0149: the security headers of every answer. */
397
405
  #security;
@@ -1587,6 +1595,8 @@ class WebOwner {
1587
1595
  if (!this.options.listen) {
1588
1596
  if (!this.#notListening) {
1589
1597
  this.#notListening = true;
1598
+ if (!this.#draining && !this.#closed)
1599
+ this.#keepAlive = setInterval(() => undefined, KEEP_ALIVE_MS);
1590
1600
  this.context.logger.log('info', 'Web server not listening', {
1591
1601
  code: 'WEB_NOT_LISTENING',
1592
1602
  reason: 'listen: false',
@@ -1607,11 +1617,14 @@ class WebOwner {
1607
1617
  // info, with every bound address: `dokebi start` reads it to show where the app answers.
1608
1618
  // `localhost` binds both 127.0.0.1 and ::1, so there can be more than one.
1609
1619
  const scheme = this.#https ? 'https' : 'http';
1620
+ // fastify 5.12.8 types an entry as `AddressInfo | string` (a pipe or socket path, kept as is).
1610
1621
  const urls = this.server
1611
1622
  .addresses()
1612
- .map((bound) => bound.family === 'IPv6' || bound.family === 6
1613
- ? `${scheme}://[${bound.address}]:${bound.port}`
1614
- : `${scheme}://${bound.address}:${bound.port}`);
1623
+ .map((bound) => typeof bound === 'string'
1624
+ ? bound
1625
+ : bound.family === 'IPv6' || bound.family === 6
1626
+ ? `${scheme}://[${bound.address}]:${bound.port}`
1627
+ : `${scheme}://${bound.address}:${bound.port}`);
1615
1628
  this.context.logger.log('info', 'Web server listening', {
1616
1629
  address: this.#address,
1617
1630
  urls: urls.length ? urls : [this.#address],
@@ -1621,6 +1634,7 @@ class WebOwner {
1621
1634
  }
1622
1635
  async drain(signal, deadline) {
1623
1636
  this.#draining = true;
1637
+ this.#releaseProcess();
1624
1638
  this.#frozen = true;
1625
1639
  const started = performance.now();
1626
1640
  const logger = this.context.logger;
@@ -2414,8 +2428,16 @@ class WebOwner {
2414
2428
  json: () => JSON.parse(response.body),
2415
2429
  });
2416
2430
  }
2431
+ /** Lets the process end once nothing else holds it (`listen: false`, D-0221). */
2432
+ #releaseProcess() {
2433
+ if (this.#keepAlive === undefined)
2434
+ return;
2435
+ clearInterval(this.#keepAlive);
2436
+ this.#keepAlive = undefined;
2437
+ }
2417
2438
  async close() {
2418
2439
  this.#closed = true;
2440
+ this.#releaseProcess();
2419
2441
  const started = performance.now();
2420
2442
  const { ended } = this.#connections.close();
2421
2443
  try {
@@ -2611,7 +2633,7 @@ class WebRuntime {
2611
2633
  }
2612
2634
  export const createPlugin = definePlugin({
2613
2635
  name: 'dokebi-web',
2614
- version: '0.4.8',
2636
+ version: '0.4.10',
2615
2637
  core: '^0.4.2',
2616
2638
  options: declaration,
2617
2639
  entry: (input) => new WebEntryInput(input),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/web",
3
- "version": "0.4.8",
3
+ "version": "0.4.10",
4
4
  "description": "Fastify 5 HTTP server owned by a Dokebi app: 503 before ready, health routes, drain and cluster handover.",
5
5
  "keywords": [
6
6
  "dokebi",
@@ -45,7 +45,8 @@
45
45
  "test": "node -e \"require('node:fs').rmSync('.tmp/tests',{recursive:true,force:true})\" && tsc -p tsconfig.test.json && node --test .tmp/tests/tests/*.test.js"
46
46
  },
47
47
  "peerDependencies": {
48
- "@dokebi/core": "^0.4.2"
48
+ "@dokebi/core": "^0.4.2",
49
+ "fastify": "5.12.8"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@dokebi/health": "0.4.1"
@@ -97,8 +98,7 @@
97
98
  ]
98
99
  },
99
100
  "dependencies": {
100
- "@fastify/under-pressure": "9.2.0",
101
- "fastify": "5.12.7"
101
+ "@fastify/under-pressure": "9.2.0"
102
102
  },
103
103
  "publishConfig": {
104
104
  "access": "public",