@platformatic/node 2.3.1 → 3.4.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.
Files changed (3) hide show
  1. package/index.js +38 -27
  2. package/package.json +7 -7
  3. package/schema.json +1 -1
package/index.js CHANGED
@@ -48,10 +48,14 @@ export class NodeStackable extends BaseStackable {
48
48
  #module
49
49
  #app
50
50
  #server
51
+ #basePath
51
52
  #dispatcher
52
53
  #isFastify
53
54
  #isKoa
54
55
 
56
+ #startHttpTimer
57
+ #endHttpTimer
58
+
55
59
  constructor (options, root, configManager) {
56
60
  super('nodejs', packageJson.version, options, root, configManager)
57
61
  }
@@ -81,7 +85,7 @@ export class NodeStackable extends BaseStackable {
81
85
  const finalEntrypoint = await this._findEntrypoint()
82
86
 
83
87
  // Require the application
84
- const basePath = config.application?.basePath
88
+ this.#basePath = config.application?.basePath
85
89
  ? ensureTrailingSlash(cleanBasePath(config.application?.basePath))
86
90
  : undefined
87
91
 
@@ -89,7 +93,7 @@ export class NodeStackable extends BaseStackable {
89
93
  // Always use URL to avoid serialization problem in Windows
90
94
  id: this.id,
91
95
  root: pathToFileURL(this.root).toString(),
92
- basePath,
96
+ basePath: this.#basePath,
93
97
  logLevel: this.logger.level
94
98
  })
95
99
 
@@ -162,11 +166,11 @@ export class NodeStackable extends BaseStackable {
162
166
  })
163
167
  }
164
168
 
165
- async collectMetrics () {
166
- return {
167
- defaultMetrics: true,
168
- httpMetrics: true
169
- }
169
+ async collectMetrics ({ startHttpTimer, endHttpTimer }) {
170
+ this.#startHttpTimer = startHttpTimer
171
+ this.#endHttpTimer = endHttpTimer
172
+
173
+ return { defaultMetrics: true, httpMetrics: true }
170
174
  }
171
175
 
172
176
  async build () {
@@ -195,12 +199,30 @@ export class NodeStackable extends BaseStackable {
195
199
  if (this.url) {
196
200
  this.logger.trace({ injectParams, url: this.url }, 'injecting via request')
197
201
  res = await injectViaRequest(this.url, injectParams, onInject)
198
- } else if (this.#isFastify) {
199
- this.logger.trace({ injectParams }, 'injecting via fastify')
200
- res = await this.#app.inject(injectParams, onInject)
201
202
  } else {
202
- this.logger.trace({ injectParams }, 'injecting via light-my-request')
203
- res = await inject(this.#dispatcher ?? this.#app, injectParams, onInject)
203
+ if (this.#startHttpTimer && this.#endHttpTimer) {
204
+ this.#startHttpTimer({ request: injectParams })
205
+
206
+ if (onInject) {
207
+ const originalOnInject = onInject
208
+ onInject = (err, response) => {
209
+ this.#endHttpTimer({ request: injectParams, response })
210
+ originalOnInject(err, response)
211
+ }
212
+ }
213
+ }
214
+
215
+ if (this.#isFastify) {
216
+ this.logger.trace({ injectParams }, 'injecting via fastify')
217
+ res = await this.#app.inject(injectParams, onInject)
218
+ } else {
219
+ this.logger.trace({ injectParams }, 'injecting via light-my-request')
220
+ res = await inject(this.#dispatcher ?? this.#app, injectParams, onInject)
221
+ }
222
+
223
+ if (this.#endHttpTimer && !onInject) {
224
+ this.#endHttpTimer({ request: injectParams, response: res })
225
+ }
204
226
  }
205
227
 
206
228
  /* c8 ignore next 3 */
@@ -220,26 +242,15 @@ export class NodeStackable extends BaseStackable {
220
242
  }
221
243
 
222
244
  getMeta () {
223
- const config = this.configManager.current
224
- const basePath = ensureTrailingSlash(cleanBasePath(this.basePath ?? config.application?.basePath))
225
-
226
- let composer = {
227
- prefix: basePath,
228
- wantsAbsoluteUrls: this._getWantsAbsoluteUrls(),
229
- needsRootRedirect: true
230
- }
231
-
232
- if (this.url) {
233
- composer = {
234
- tcp: true,
245
+ return {
246
+ composer: {
247
+ tcp: typeof this.url !== 'undefined',
235
248
  url: this.url,
236
- prefix: basePath,
249
+ prefix: this.basePath ?? this.#basePath,
237
250
  wantsAbsoluteUrls: this._getWantsAbsoluteUrls(),
238
251
  needsRootRedirect: true
239
252
  }
240
253
  }
241
-
242
- return { composer }
243
254
  }
244
255
 
245
256
  async _listen () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/node",
3
- "version": "2.3.1",
3
+ "version": "3.4.1",
4
4
  "description": "Platformatic Node.js Stackable",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,10 +16,10 @@
16
16
  "homepage": "https://github.com/platformatic/platformatic#readme",
17
17
  "dependencies": {
18
18
  "light-my-request": "^6.0.0",
19
- "@platformatic/basic": "2.3.1",
20
- "@platformatic/utils": "2.3.1",
21
- "@platformatic/config": "2.3.1",
22
- "@platformatic/telemetry": "2.3.1"
19
+ "@platformatic/basic": "3.4.1",
20
+ "@platformatic/config": "3.4.1",
21
+ "@platformatic/telemetry": "3.4.1",
22
+ "@platformatic/utils": "3.4.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "borp": "^0.17.0",
@@ -31,8 +31,8 @@
31
31
  "neostandard": "^0.11.1",
32
32
  "tsx": "^4.19.0",
33
33
  "typescript": "^5.5.4",
34
- "@platformatic/composer": "2.3.1",
35
- "@platformatic/service": "2.3.1"
34
+ "@platformatic/composer": "3.4.1",
35
+ "@platformatic/service": "3.4.1"
36
36
  },
37
37
  "scripts": {
38
38
  "test": "npm run lint && borp --concurrency=1 --no-timeout",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/node/2.3.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/node/3.4.1.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Node.js Stackable",
5
5
  "type": "object",