@platformatic/node 2.22.0 → 2.24.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/index.js +25 -3
- package/package.json +7 -7
- package/schema.json +1 -1
package/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
cleanBasePath,
|
|
4
4
|
createServerListener,
|
|
5
5
|
ensureTrailingSlash,
|
|
6
|
+
getAsyncLocalStorageSnapshot,
|
|
6
7
|
getServerUrl,
|
|
7
8
|
importFile,
|
|
8
9
|
injectViaRequest,
|
|
@@ -10,7 +11,9 @@ import {
|
|
|
10
11
|
transformConfig
|
|
11
12
|
} from '@platformatic/basic'
|
|
12
13
|
import { ConfigManager } from '@platformatic/config'
|
|
14
|
+
import { features } from '@platformatic/utils'
|
|
13
15
|
import inject from 'light-my-request'
|
|
16
|
+
import { AsyncResource } from 'node:async_hooks'
|
|
14
17
|
import { existsSync } from 'node:fs'
|
|
15
18
|
import { readFile } from 'node:fs/promises'
|
|
16
19
|
import { Server } from 'node:http'
|
|
@@ -86,7 +89,7 @@ export class NodeStackable extends BaseStackable {
|
|
|
86
89
|
: undefined
|
|
87
90
|
|
|
88
91
|
this.registerGlobals({
|
|
89
|
-
basePath: this.#basePath
|
|
92
|
+
basePath: this.#basePath
|
|
90
93
|
})
|
|
91
94
|
|
|
92
95
|
// The server promise must be created before requiring the entrypoint even if it's not going to be used
|
|
@@ -130,6 +133,7 @@ export class NodeStackable extends BaseStackable {
|
|
|
130
133
|
this.url = getServerUrl(this.#server)
|
|
131
134
|
}
|
|
132
135
|
|
|
136
|
+
this._collectMetrics()
|
|
133
137
|
return this.url
|
|
134
138
|
}
|
|
135
139
|
|
|
@@ -180,6 +184,19 @@ export class NodeStackable extends BaseStackable {
|
|
|
180
184
|
}
|
|
181
185
|
|
|
182
186
|
async inject (injectParams, onInject) {
|
|
187
|
+
const snapshot = this.#server && getAsyncLocalStorageSnapshot(this.#server)
|
|
188
|
+
if (!snapshot) {
|
|
189
|
+
return this.#inject(injectParams, onInject)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return snapshot(() => {
|
|
193
|
+
// Need to new resource so each inject has separate context
|
|
194
|
+
const resource = new AsyncResource('PLTNodeStackable')
|
|
195
|
+
return resource.runInAsyncScope(this.#inject, this, injectParams, onInject)
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async #inject (injectParams, onInject) {
|
|
183
200
|
let res
|
|
184
201
|
|
|
185
202
|
if (this.#useHttpForDispatch) {
|
|
@@ -253,15 +270,20 @@ export class NodeStackable extends BaseStackable {
|
|
|
253
270
|
|
|
254
271
|
async _listen () {
|
|
255
272
|
const serverOptions = this.serverConfig
|
|
273
|
+
const listenOptions = { host: serverOptions?.hostname || '127.0.0.1', port: serverOptions?.port || 0 }
|
|
274
|
+
|
|
275
|
+
if (this.isProduction && features.node.reusePort) {
|
|
276
|
+
listenOptions.reusePort = true
|
|
277
|
+
}
|
|
256
278
|
|
|
257
279
|
if (this.#isFastify) {
|
|
258
|
-
await this.#app.listen(
|
|
280
|
+
await this.#app.listen(listenOptions)
|
|
259
281
|
this.url = getServerUrl(this.#app.server)
|
|
260
282
|
} else {
|
|
261
283
|
// Express / Node / Koa
|
|
262
284
|
this.#server = await new Promise((resolve, reject) => {
|
|
263
285
|
return this.#app
|
|
264
|
-
.listen(
|
|
286
|
+
.listen(listenOptions, function () {
|
|
265
287
|
resolve(this)
|
|
266
288
|
})
|
|
267
289
|
.on('error', reject)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/node",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.24.0",
|
|
4
4
|
"description": "Platformatic Node.js Stackable",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"homepage": "https://github.com/platformatic/platformatic#readme",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"light-my-request": "^6.0.0",
|
|
19
|
-
"@platformatic/basic": "2.
|
|
20
|
-
"@platformatic/config": "2.
|
|
21
|
-
"@platformatic/utils": "2.
|
|
19
|
+
"@platformatic/basic": "2.24.0",
|
|
20
|
+
"@platformatic/config": "2.24.0",
|
|
21
|
+
"@platformatic/utils": "2.24.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"borp": "^0.19.0",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"fastify": "^5.0.0",
|
|
28
28
|
"json-schema-to-typescript": "^15.0.1",
|
|
29
29
|
"koa": "^2.15.3",
|
|
30
|
-
"neostandard": "^0.
|
|
30
|
+
"neostandard": "^0.12.0",
|
|
31
31
|
"tsx": "^4.19.0",
|
|
32
32
|
"typescript": "^5.5.4",
|
|
33
|
-
"@platformatic/composer": "2.
|
|
34
|
-
"@platformatic/service": "2.
|
|
33
|
+
"@platformatic/composer": "2.24.0",
|
|
34
|
+
"@platformatic/service": "2.24.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"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.
|
|
2
|
+
"$id": "https://schemas.platformatic.dev/@platformatic/node/2.24.0.json",
|
|
3
3
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
4
|
"title": "Platformatic Node.js Stackable",
|
|
5
5
|
"type": "object",
|