@platformatic/nest 3.33.0 → 3.34.1-alpha.3

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/config.d.ts CHANGED
@@ -231,6 +231,10 @@ export interface PlatformaticNestJSConfig {
231
231
  gracefulShutdown?: {
232
232
  runtime: number | string;
233
233
  application: number | string;
234
+ /**
235
+ * Add Connection: close header to HTTP responses during graceful shutdown
236
+ */
237
+ closeConnections?: boolean;
234
238
  };
235
239
  health?: {
236
240
  enabled?: boolean | string;
@@ -394,6 +398,23 @@ export interface PlatformaticNestJSConfig {
394
398
  */
395
399
  serviceVersion?: string;
396
400
  };
401
+ /**
402
+ * Custom labels to add to HTTP metrics (http_request_all_duration_seconds). Each label extracts its value from an HTTP request header.
403
+ */
404
+ httpCustomLabels?: {
405
+ /**
406
+ * The label name to use in metrics
407
+ */
408
+ name: string;
409
+ /**
410
+ * The HTTP request header to extract the value from
411
+ */
412
+ header: string;
413
+ /**
414
+ * Default value when header is missing (defaults to "unknown")
415
+ */
416
+ default?: string;
417
+ }[];
397
418
  };
398
419
  telemetry?: {
399
420
  enabled?: boolean | string;
package/lib/capability.js CHANGED
@@ -103,6 +103,32 @@ export class NestCapability extends BaseCapability {
103
103
  return this._closeServer(this.#server)
104
104
  }
105
105
 
106
+ setClosing () {
107
+ super.setClosing()
108
+
109
+ if (!this.#server) return
110
+
111
+ const closeConnections = this.runtimeConfig?.gracefulShutdown?.closeConnections !== false
112
+ if (!closeConnections) return
113
+
114
+ // For non-Fastify (Express) servers, add request listener to set Connection: close
115
+ if (!this.#isFastify) {
116
+ const self = this
117
+ this.#server.on('request', (req, res) => {
118
+ if (self.closing && !res.headersSent && req.httpVersionMajor !== 2) {
119
+ res.setHeader('Connection', 'close')
120
+ }
121
+ })
122
+ }
123
+
124
+ // For Fastify, it handles Connection: close via its own hook in ServiceCapability pattern
125
+ // but we still need to close HTTP/2 sessions
126
+ const server = this.#isFastify ? this.#server.server : this.#server
127
+ if (server?.closeHttp2Sessions) {
128
+ server.closeHttp2Sessions()
129
+ }
130
+ }
131
+
106
132
  async build () {
107
133
  if (!this.#nestjsCore) {
108
134
  await this.init()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/nest",
3
- "version": "3.33.0",
3
+ "version": "3.34.1-alpha.3",
4
4
  "description": "Platformatic Nest.js Capability",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -18,9 +18,9 @@
18
18
  "get-port": "^7.1.0",
19
19
  "light-my-request": "^6.0.0",
20
20
  "pino-http": "^10.2.0",
21
- "@platformatic/basic": "3.33.0",
22
- "@platformatic/foundation": "3.33.0",
23
- "@platformatic/generators": "3.33.0"
21
+ "@platformatic/basic": "3.34.1-alpha.3",
22
+ "@platformatic/generators": "3.34.1-alpha.3",
23
+ "@platformatic/foundation": "3.34.1-alpha.3"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@nestjs/cli": "^11.0.7",
@@ -33,8 +33,8 @@
33
33
  "neostandard": "^0.12.0",
34
34
  "tsx": "^4.19.0",
35
35
  "typescript": "^5.5.4",
36
- "@platformatic/gateway": "3.33.0",
37
- "@platformatic/service": "3.33.0"
36
+ "@platformatic/gateway": "3.34.1-alpha.3",
37
+ "@platformatic/service": "3.34.1-alpha.3"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=22.19.0"
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/nest/3.33.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/nest/3.34.1-alpha.3.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic NestJS Config",
5
5
  "type": "object",
@@ -1111,6 +1111,11 @@
1111
1111
  }
1112
1112
  ],
1113
1113
  "default": 10000
1114
+ },
1115
+ "closeConnections": {
1116
+ "type": "boolean",
1117
+ "default": true,
1118
+ "description": "Add Connection: close header to HTTP responses during graceful shutdown"
1114
1119
  }
1115
1120
  },
1116
1121
  "default": {},
@@ -1651,6 +1656,32 @@
1651
1656
  "endpoint"
1652
1657
  ],
1653
1658
  "additionalProperties": false
1659
+ },
1660
+ "httpCustomLabels": {
1661
+ "type": "array",
1662
+ "description": "Custom labels to add to HTTP metrics (http_request_all_duration_seconds). Each label extracts its value from an HTTP request header.",
1663
+ "items": {
1664
+ "type": "object",
1665
+ "properties": {
1666
+ "name": {
1667
+ "type": "string",
1668
+ "description": "The label name to use in metrics"
1669
+ },
1670
+ "header": {
1671
+ "type": "string",
1672
+ "description": "The HTTP request header to extract the value from"
1673
+ },
1674
+ "default": {
1675
+ "type": "string",
1676
+ "description": "Default value when header is missing (defaults to \"unknown\")"
1677
+ }
1678
+ },
1679
+ "required": [
1680
+ "name",
1681
+ "header"
1682
+ ],
1683
+ "additionalProperties": false
1684
+ }
1654
1685
  }
1655
1686
  },
1656
1687
  "additionalProperties": false