@platformatic/node 2.0.0-alpha.14 → 2.0.0-alpha.16

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
@@ -7,86 +7,48 @@
7
7
 
8
8
  export interface PlatformaticNodeJsStackable {
9
9
  $schema?: string;
10
- server?: {
11
- hostname?: string;
12
- port?: number | string;
13
- pluginTimeout?: number;
14
- healthCheck?:
15
- | boolean
10
+ logger?: {
11
+ level: (
12
+ | ("fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent")
16
13
  | {
17
- enabled?: boolean;
18
- interval?: number;
19
14
  [k: string]: unknown;
20
- };
21
- ignoreTrailingSlash?: boolean;
22
- ignoreDuplicateSlashes?: boolean;
23
- connectionTimeout?: number;
24
- keepAliveTimeout?: number;
25
- maxRequestsPerSocket?: number;
26
- forceCloseConnections?: boolean | string;
27
- requestTimeout?: number;
28
- bodyLimit?: number;
29
- maxParamLength?: number;
30
- disableRequestLogging?: boolean;
31
- exposeHeadRoutes?: boolean;
32
- logger?:
33
- | boolean
15
+ }
16
+ ) &
17
+ string;
18
+ transport?:
34
19
  | {
35
- level?: string;
36
- transport?:
37
- | {
38
- target?: string;
39
- options?: {
40
- [k: string]: unknown;
41
- };
42
- }
43
- | {
44
- targets?: {
45
- target?: string;
46
- options?: {
47
- [k: string]: unknown;
48
- };
49
- level?: string;
50
- additionalProperties?: never;
51
- [k: string]: unknown;
52
- }[];
53
- options?: {
54
- [k: string]: unknown;
55
- };
56
- };
57
- pipeline?: {
20
+ target?: string;
21
+ options?: {
22
+ [k: string]: unknown;
23
+ };
24
+ }
25
+ | {
26
+ targets?: {
58
27
  target?: string;
59
28
  options?: {
60
29
  [k: string]: unknown;
61
30
  };
31
+ level?: string;
32
+ additionalProperties?: never;
33
+ [k: string]: unknown;
34
+ }[];
35
+ options?: {
36
+ [k: string]: unknown;
62
37
  };
63
- [k: string]: unknown;
64
38
  };
65
- loggerInstance?: {
66
- [k: string]: unknown;
67
- };
68
- serializerOpts?: {
69
- schema?: {
39
+ pipeline?: {
40
+ target?: string;
41
+ options?: {
70
42
  [k: string]: unknown;
71
43
  };
72
- ajv?: {
73
- [k: string]: unknown;
74
- };
75
- rounding?: "floor" | "ceil" | "round" | "trunc";
76
- debugMode?: boolean;
77
- mode?: "debug" | "standalone";
78
- largeArraySize?: number | string;
79
- largeArrayMechanism?: "default" | "json-stringify";
80
- [k: string]: unknown;
81
44
  };
82
- caseSensitive?: boolean;
83
- requestIdHeader?: string | false;
84
- requestIdLogLabel?: string;
85
- jsonShorthand?: boolean;
86
- trustProxy?: boolean | string | string[] | number;
45
+ [k: string]: unknown;
46
+ };
47
+ server?: {
48
+ hostname?: string;
49
+ port?: number | string;
87
50
  http2?: boolean;
88
51
  https?: {
89
- allowHTTP1?: boolean;
90
52
  key:
91
53
  | string
92
54
  | {
@@ -109,37 +71,6 @@ export interface PlatformaticNodeJsStackable {
109
71
  path?: string;
110
72
  }
111
73
  )[];
112
- requestCert?: boolean;
113
- rejectUnauthorized?: boolean;
114
- };
115
- cors?: {
116
- origin?:
117
- | boolean
118
- | string
119
- | (
120
- | string
121
- | {
122
- regexp: string;
123
- [k: string]: unknown;
124
- }
125
- )[]
126
- | {
127
- regexp: string;
128
- [k: string]: unknown;
129
- };
130
- methods?: string[];
131
- /**
132
- * Comma separated string of allowed headers.
133
- */
134
- allowedHeaders?: string;
135
- exposedHeaders?: string[] | string;
136
- credentials?: boolean;
137
- maxAge?: number;
138
- preflightContinue?: boolean;
139
- optionsSuccessStatus?: number;
140
- preflight?: boolean;
141
- strictPreflight?: boolean;
142
- hideOptionsRoute?: boolean;
143
74
  };
144
75
  };
145
76
  watch?:
@@ -165,6 +96,10 @@ export interface PlatformaticNodeJsStackable {
165
96
  };
166
97
  };
167
98
  node?: {
168
- entrypoint?: string;
99
+ main?: string;
100
+ /**
101
+ * This Node.js application requires the Absolute URL from the Composer
102
+ */
103
+ absoluteUrl?: boolean;
169
104
  };
170
105
  }
package/index.js CHANGED
@@ -167,10 +167,13 @@ export class NodeStackable extends BaseStackable {
167
167
  let res
168
168
 
169
169
  if (this.url) {
170
+ this.logger.trace({ injectParams, url: this.url }, 'injecting via request')
170
171
  res = await injectViaRequest(this.url, injectParams, onInject)
171
172
  } else if (this.#isFastify) {
173
+ this.logger.trace({ injectParams }, 'injecting via fastify')
172
174
  res = await this.#app.inject(injectParams, onInject)
173
175
  } else {
176
+ this.logger.trace({ injectParams }, 'injecting via light-my-request')
174
177
  res = await inject(this.#dispatcher ?? this.#app, injectParams, onInject)
175
178
  }
176
179
 
@@ -185,9 +188,18 @@ export class NodeStackable extends BaseStackable {
185
188
  return { statusCode, headers, body, payload, rawPayload }
186
189
  }
187
190
 
191
+ _getWantsAbsoluteUrls () {
192
+ const config = this.configManager.current
193
+ return config.node.absoluteUrl
194
+ }
195
+
188
196
  getMeta () {
189
197
  const config = this.configManager.current
190
- let composer = { prefix: this.servicePrefix, wantsAbsoluteUrls: true, needsRootRedirect: true }
198
+ let composer = {
199
+ prefix: this.servicePrefix,
200
+ wantsAbsoluteUrls: this._getWantsAbsoluteUrls(),
201
+ needsRootRedirect: true
202
+ }
191
203
 
192
204
  if (this.url) {
193
205
  composer = {
@@ -196,7 +208,7 @@ export class NodeStackable extends BaseStackable {
196
208
  prefix: config.application?.basePath
197
209
  ? ensureTrailingSlash(cleanBasePath(config.application?.basePath))
198
210
  : this.servicePrefix,
199
- wantsAbsoluteUrls: true,
211
+ wantsAbsoluteUrls: this._getWantsAbsoluteUrls(),
200
212
  needsRootRedirect: true
201
213
  }
202
214
  }
@@ -234,8 +246,8 @@ export class NodeStackable extends BaseStackable {
234
246
  const config = this.configManager.current
235
247
  const outputRoot = resolve(this.root, config.application.outputDirectory)
236
248
 
237
- if (config.node.entrypoint) {
238
- return pathResolve(this.root, config.node.entrypoint)
249
+ if (config.node.main) {
250
+ return pathResolve(this.root, config.node.main)
239
251
  }
240
252
 
241
253
  const { entrypoint, hadEntrypointField } = await getEntrypointInformation(this.root)
@@ -333,7 +345,13 @@ async function getEntrypointInformation (root) {
333
345
  export async function buildStackable (opts) {
334
346
  const root = opts.context.directory
335
347
 
336
- const configManager = new ConfigManager({ schema, source: opts.config ?? {}, schemaOptions, transformConfig })
348
+ const configManager = new ConfigManager({
349
+ schema,
350
+ source: opts.config ?? {},
351
+ schemaOptions,
352
+ transformConfig,
353
+ dirname: root
354
+ })
337
355
  await configManager.parseAndValidate()
338
356
 
339
357
  return new NodeStackable(opts, root, configManager)
package/lib/schema.js CHANGED
@@ -7,8 +7,13 @@ export const packageJson = JSON.parse(readFileSync(new URL('../package.json', im
7
7
  const node = {
8
8
  type: 'object',
9
9
  properties: {
10
- entrypoint: {
11
- type: 'string'
10
+ main: {
11
+ type: 'string',
12
+ },
13
+ absoluteUrl: {
14
+ description: 'This Node.js application requires the Absolute URL from the Composer',
15
+ type: 'boolean',
16
+ default: false,
12
17
  }
13
18
  },
14
19
  default: {},
@@ -18,7 +23,7 @@ const node = {
18
23
  export const schemaComponents = { node }
19
24
 
20
25
  export const schema = {
21
- $id: `https://schemas.platformatic.dev/@platformatic/vite/${packageJson.version}.json`,
26
+ $id: `https://schemas.platformatic.dev/@platformatic/node/${packageJson.version}.json`,
22
27
  $schema: 'http://json-schema.org/draft-07/schema#',
23
28
  title: 'Platformatic Node.js Stackable',
24
29
  type: 'object',
@@ -26,6 +31,7 @@ export const schema = {
26
31
  $schema: {
27
32
  type: 'string'
28
33
  },
34
+ logger: utilsSchemaComponents.logger,
29
35
  server: utilsSchemaComponents.server,
30
36
  watch: basicSchemaComponents.watch,
31
37
  application: basicSchemaComponents.application,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/node",
3
- "version": "2.0.0-alpha.14",
3
+ "version": "2.0.0-alpha.16",
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.0.0-alpha.14",
20
- "@platformatic/utils": "2.0.0-alpha.14",
21
- "@platformatic/config": "2.0.0-alpha.14"
19
+ "@platformatic/basic": "2.0.0-alpha.16",
20
+ "@platformatic/utils": "2.0.0-alpha.16",
21
+ "@platformatic/config": "2.0.0-alpha.16"
22
22
  },
23
23
  "devDependencies": {
24
24
  "borp": "^0.17.0",
@@ -29,8 +29,8 @@
29
29
  "neostandard": "^0.11.1",
30
30
  "tsx": "^4.19.0",
31
31
  "typescript": "^5.5.4",
32
- "@platformatic/composer": "2.0.0-alpha.14",
33
- "@platformatic/service": "2.0.0-alpha.14"
32
+ "@platformatic/composer": "2.0.0-alpha.16",
33
+ "@platformatic/service": "2.0.0-alpha.16"
34
34
  },
35
35
  "scripts": {
36
36
  "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/vite/2.0.0-alpha.14.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/node/2.0.0-alpha.16.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Node.js Stackable",
5
5
  "type": "object",
@@ -7,249 +7,108 @@
7
7
  "$schema": {
8
8
  "type": "string"
9
9
  },
10
- "server": {
10
+ "logger": {
11
11
  "type": "object",
12
12
  "properties": {
13
- "hostname": {
14
- "type": "string"
15
- },
16
- "port": {
17
- "anyOf": [
13
+ "level": {
14
+ "type": "string",
15
+ "default": "info",
16
+ "oneOf": [
18
17
  {
19
- "type": "integer"
18
+ "enum": [
19
+ "fatal",
20
+ "error",
21
+ "warn",
22
+ "info",
23
+ "debug",
24
+ "trace",
25
+ "silent"
26
+ ]
20
27
  },
21
28
  {
22
- "type": "string"
29
+ "pattern": "^\\{.+\\}$"
23
30
  }
24
31
  ]
25
32
  },
26
- "pluginTimeout": {
27
- "type": "integer"
28
- },
29
- "healthCheck": {
33
+ "transport": {
30
34
  "anyOf": [
31
- {
32
- "type": "boolean"
33
- },
34
35
  {
35
36
  "type": "object",
36
37
  "properties": {
37
- "enabled": {
38
- "type": "boolean"
38
+ "target": {
39
+ "type": "string",
40
+ "resolveModule": true
39
41
  },
40
- "interval": {
41
- "type": "integer"
42
+ "options": {
43
+ "type": "object"
42
44
  }
43
45
  },
44
- "additionalProperties": true
45
- }
46
- ]
47
- },
48
- "ignoreTrailingSlash": {
49
- "type": "boolean"
50
- },
51
- "ignoreDuplicateSlashes": {
52
- "type": "boolean"
53
- },
54
- "connectionTimeout": {
55
- "type": "integer"
56
- },
57
- "keepAliveTimeout": {
58
- "type": "integer",
59
- "default": 5000
60
- },
61
- "maxRequestsPerSocket": {
62
- "type": "integer"
63
- },
64
- "forceCloseConnections": {
65
- "anyOf": [
66
- {
67
- "type": "boolean"
68
- },
69
- {
70
- "type": "string",
71
- "pattern": "^idle$"
72
- }
73
- ]
74
- },
75
- "requestTimeout": {
76
- "type": "integer"
77
- },
78
- "bodyLimit": {
79
- "type": "integer"
80
- },
81
- "maxParamLength": {
82
- "type": "integer"
83
- },
84
- "disableRequestLogging": {
85
- "type": "boolean"
86
- },
87
- "exposeHeadRoutes": {
88
- "type": "boolean"
89
- },
90
- "logger": {
91
- "anyOf": [
92
- {
93
- "type": "boolean"
46
+ "additionalProperties": false
94
47
  },
95
48
  {
96
49
  "type": "object",
97
50
  "properties": {
98
- "level": {
99
- "type": "string"
100
- },
101
- "transport": {
102
- "anyOf": [
103
- {
104
- "type": "object",
105
- "properties": {
106
- "target": {
107
- "type": "string",
108
- "resolveModule": true
109
- },
110
- "options": {
111
- "type": "object"
112
- }
51
+ "targets": {
52
+ "type": "array",
53
+ "items": {
54
+ "type": "object",
55
+ "properties": {
56
+ "target": {
57
+ "type": "string",
58
+ "resolveModule": true
113
59
  },
114
- "additionalProperties": false
115
- },
116
- {
117
- "type": "object",
118
- "properties": {
119
- "targets": {
120
- "type": "array",
121
- "items": {
122
- "type": "object",
123
- "properties": {
124
- "target": {
125
- "type": "string",
126
- "resolveModule": true
127
- },
128
- "options": {
129
- "type": "object"
130
- },
131
- "level": {
132
- "type": "string"
133
- },
134
- "additionalProperties": false
135
- }
136
- }
137
- },
138
- "options": {
139
- "type": "object"
140
- }
60
+ "options": {
61
+ "type": "object"
62
+ },
63
+ "level": {
64
+ "type": "string"
141
65
  },
142
66
  "additionalProperties": false
143
67
  }
144
- ]
68
+ }
145
69
  },
146
- "pipeline": {
147
- "type": "object",
148
- "properties": {
149
- "target": {
150
- "type": "string",
151
- "resolveModule": true
152
- },
153
- "options": {
154
- "type": "object"
155
- }
156
- },
157
- "additionalProperties": false
70
+ "options": {
71
+ "type": "object"
158
72
  }
159
73
  },
160
- "additionalProperties": true
74
+ "additionalProperties": false
161
75
  }
162
76
  ]
163
77
  },
164
- "loggerInstance": {
165
- "type": "object"
166
- },
167
- "serializerOpts": {
78
+ "pipeline": {
168
79
  "type": "object",
169
80
  "properties": {
170
- "schema": {
171
- "type": "object"
172
- },
173
- "ajv": {
174
- "type": "object"
175
- },
176
- "rounding": {
177
- "type": "string",
178
- "enum": [
179
- "floor",
180
- "ceil",
181
- "round",
182
- "trunc"
183
- ],
184
- "default": "trunc"
185
- },
186
- "debugMode": {
187
- "type": "boolean"
188
- },
189
- "mode": {
81
+ "target": {
190
82
  "type": "string",
191
- "enum": [
192
- "debug",
193
- "standalone"
194
- ]
195
- },
196
- "largeArraySize": {
197
- "anyOf": [
198
- {
199
- "type": "integer"
200
- },
201
- {
202
- "type": "string"
203
- }
204
- ],
205
- "default": 20000
83
+ "resolveModule": true
206
84
  },
207
- "largeArrayMechanism": {
208
- "type": "string",
209
- "enum": [
210
- "default",
211
- "json-stringify"
212
- ],
213
- "default": "default"
214
- }
215
- }
216
- },
217
- "caseSensitive": {
218
- "type": "boolean"
219
- },
220
- "requestIdHeader": {
221
- "anyOf": [
222
- {
223
- "type": "string"
224
- },
225
- {
226
- "type": "boolean",
227
- "const": false
85
+ "options": {
86
+ "type": "object"
228
87
  }
229
- ]
230
- },
231
- "requestIdLogLabel": {
232
- "type": "string"
233
- },
234
- "jsonShorthand": {
235
- "type": "boolean"
88
+ },
89
+ "additionalProperties": false
90
+ }
91
+ },
92
+ "required": [
93
+ "level"
94
+ ],
95
+ "default": {},
96
+ "additionalProperties": true
97
+ },
98
+ "server": {
99
+ "type": "object",
100
+ "properties": {
101
+ "hostname": {
102
+ "type": "string",
103
+ "default": "127.0.0.1"
236
104
  },
237
- "trustProxy": {
105
+ "port": {
238
106
  "anyOf": [
239
107
  {
240
- "type": "boolean"
108
+ "type": "integer"
241
109
  },
242
110
  {
243
111
  "type": "string"
244
- },
245
- {
246
- "type": "array",
247
- "items": {
248
- "type": "string"
249
- }
250
- },
251
- {
252
- "type": "integer"
253
112
  }
254
113
  ]
255
114
  },
@@ -259,9 +118,6 @@
259
118
  "https": {
260
119
  "type": "object",
261
120
  "properties": {
262
- "allowHTTP1": {
263
- "type": "boolean"
264
- },
265
121
  "key": {
266
122
  "anyOf": [
267
123
  {
@@ -335,12 +191,6 @@
335
191
  }
336
192
  }
337
193
  ]
338
- },
339
- "requestCert": {
340
- "type": "boolean"
341
- },
342
- "rejectUnauthorized": {
343
- "type": "boolean"
344
194
  }
345
195
  },
346
196
  "additionalProperties": false,
@@ -348,105 +198,6 @@
348
198
  "key",
349
199
  "cert"
350
200
  ]
351
- },
352
- "cors": {
353
- "type": "object",
354
- "$comment": "See https://github.com/fastify/fastify-cors",
355
- "properties": {
356
- "origin": {
357
- "anyOf": [
358
- {
359
- "type": "boolean"
360
- },
361
- {
362
- "type": "string"
363
- },
364
- {
365
- "type": "array",
366
- "items": {
367
- "anyOf": [
368
- {
369
- "type": "string"
370
- },
371
- {
372
- "type": "object",
373
- "properties": {
374
- "regexp": {
375
- "type": "string"
376
- }
377
- },
378
- "required": [
379
- "regexp"
380
- ]
381
- }
382
- ]
383
- }
384
- },
385
- {
386
- "type": "object",
387
- "properties": {
388
- "regexp": {
389
- "type": "string"
390
- }
391
- },
392
- "required": [
393
- "regexp"
394
- ]
395
- }
396
- ]
397
- },
398
- "methods": {
399
- "type": "array",
400
- "items": {
401
- "type": "string"
402
- }
403
- },
404
- "allowedHeaders": {
405
- "type": "string",
406
- "description": "Comma separated string of allowed headers."
407
- },
408
- "exposedHeaders": {
409
- "anyOf": [
410
- {
411
- "type": "array",
412
- "items": {
413
- "type": "string"
414
- }
415
- },
416
- {
417
- "type": "string",
418
- "description": "Comma separated string of exposed headers."
419
- }
420
- ]
421
- },
422
- "credentials": {
423
- "type": "boolean"
424
- },
425
- "maxAge": {
426
- "type": "integer"
427
- },
428
- "preflightContinue": {
429
- "type": "boolean",
430
- "default": false
431
- },
432
- "optionsSuccessStatus": {
433
- "type": "integer",
434
- "default": 204
435
- },
436
- "preflight": {
437
- "type": "boolean",
438
- "default": true
439
- },
440
- "strictPreflight": {
441
- "type": "boolean",
442
- "default": true
443
- },
444
- "hideOptionsRoute": {
445
- "type": "boolean",
446
- "default": true
447
- }
448
- },
449
- "additionalProperties": false
450
201
  }
451
202
  },
452
203
  "additionalProperties": false
@@ -541,8 +292,13 @@
541
292
  "node": {
542
293
  "type": "object",
543
294
  "properties": {
544
- "entrypoint": {
295
+ "main": {
545
296
  "type": "string"
297
+ },
298
+ "absoluteUrl": {
299
+ "description": "This Node.js application requires the Absolute URL from the Composer",
300
+ "type": "boolean",
301
+ "default": false
546
302
  }
547
303
  },
548
304
  "default": {},