@platformatic/next 3.74.0 → 3.75.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.
package/config.d.ts CHANGED
@@ -122,6 +122,14 @@ export interface PlatformaticNextJsConfig {
122
122
  * The maximum length of the queue of pending connections
123
123
  */
124
124
  backlog?: number;
125
+ /**
126
+ * The number of milliseconds of inactivity a server needs to wait for additional incoming data, after it has finished writing the last response, before a socket will be destroyed. When running behind a load balancer, set it higher than the load balancer idle timeout.
127
+ */
128
+ keepAliveTimeout?: number;
129
+ /**
130
+ * The number of milliseconds to wait to receive the complete HTTP headers from the client. It should be greater than keepAliveTimeout.
131
+ */
132
+ headersTimeout?: number;
125
133
  http2?: boolean;
126
134
  https?: {
127
135
  allowHTTP1?: boolean;
@@ -157,8 +165,8 @@ export interface PlatformaticNextJsConfig {
157
165
  /**
158
166
  * @minItems 1
159
167
  */
160
- allow?: [string, ...string[]];
161
- ignore?: string[];
168
+ allow?: [string, ...string[]] | null;
169
+ ignore?: string[] | null;
162
170
  }
163
171
  | boolean
164
172
  | string;
@@ -199,9 +207,108 @@ export interface PlatformaticNextJsConfig {
199
207
  }
200
208
  )[];
201
209
  basePath?: string;
202
- services?: {
210
+ services?: ({
203
211
  [k: string]: unknown;
204
- }[];
212
+ } & {
213
+ id?: string;
214
+ enabled?:
215
+ | boolean
216
+ | string
217
+ | {
218
+ [k: string]: boolean;
219
+ };
220
+ path?: string;
221
+ config?: string;
222
+ url?: string;
223
+ gitBranch?: string;
224
+ useHttp?: boolean;
225
+ websocket?: boolean;
226
+ reuseTcpPorts?: boolean;
227
+ workers?:
228
+ | number
229
+ | string
230
+ | {
231
+ static?: number;
232
+ minimum?: number;
233
+ maximum?: number;
234
+ scaleUpELU?: number;
235
+ scaleDownELU?: number;
236
+ [k: string]: unknown;
237
+ };
238
+ health?: {
239
+ enabled?: boolean | string;
240
+ interval?: number | string;
241
+ gracePeriod?: number | string;
242
+ maxUnhealthyChecks?: number | string;
243
+ maxELU?: number | string;
244
+ maxEventLoopDelay?: number | string;
245
+ maxEventLoopDelayP99?: number | string;
246
+ maxHeapUsed?: number | string;
247
+ maxHeapTotal?: number | string;
248
+ maxYoungGeneration?: number | string;
249
+ codeRangeSize?: number | string;
250
+ bufferPoolSize?: number | string;
251
+ defaultHighWaterMark?: number | string;
252
+ };
253
+ /**
254
+ * Overrides the runtime-level restartOnError for this application. Set to false or 0 to never restart the application when it crashes, a positive number to wait that amount of milliseconds between restarts, or true to use the default delay.
255
+ */
256
+ restartOnError?: boolean | number;
257
+ dependencies?: string[];
258
+ arguments?: string[];
259
+ env?: {
260
+ [k: string]: string;
261
+ };
262
+ envfile?: string;
263
+ sourceMaps?: boolean;
264
+ nodeModulesSourceMaps?: string[];
265
+ packageManager?: "npm" | "pnpm" | "yarn";
266
+ preload?: string | string[];
267
+ nodeOptions?: string;
268
+ execArgv?: string[];
269
+ permissions?: {
270
+ fs?: {
271
+ read?: string[];
272
+ write?: string[];
273
+ };
274
+ };
275
+ telemetry?: {
276
+ /**
277
+ * An array of instrumentations loaded if telemetry is enabled
278
+ */
279
+ instrumentations?: (
280
+ | string
281
+ | {
282
+ package: string;
283
+ exportName?: string;
284
+ options?: {
285
+ [k: string]: unknown;
286
+ };
287
+ [k: string]: unknown;
288
+ }
289
+ )[];
290
+ [k: string]: unknown;
291
+ };
292
+ compileCache?:
293
+ | boolean
294
+ | {
295
+ /**
296
+ * Enable Node.js module compile cache for faster startup
297
+ */
298
+ enabled?: boolean;
299
+ /**
300
+ * Directory to store compile cache. Defaults to .plt/compile-cache in app root
301
+ */
302
+ directory?: string;
303
+ };
304
+ management?:
305
+ | boolean
306
+ | {
307
+ enabled?: boolean;
308
+ operations?: string[];
309
+ };
310
+ [k: string]: unknown;
311
+ })[];
205
312
  workers?:
206
313
  | number
207
314
  | string
@@ -333,6 +440,14 @@ export interface PlatformaticNextJsConfig {
333
440
  * The maximum length of the queue of pending connections
334
441
  */
335
442
  backlog?: number;
443
+ /**
444
+ * The number of milliseconds of inactivity a server needs to wait for additional incoming data, after it has finished writing the last response, before a socket will be destroyed. When running behind a load balancer, set it higher than the load balancer idle timeout.
445
+ */
446
+ keepAliveTimeout?: number;
447
+ /**
448
+ * The number of milliseconds to wait to receive the complete HTTP headers from the client. It should be greater than keepAliveTimeout.
449
+ */
450
+ headersTimeout?: number;
336
451
  http2?: boolean;
337
452
  https?: {
338
453
  allowHTTP1?: boolean;
@@ -755,6 +870,32 @@ export interface PlatformaticNextJsConfig {
755
870
  * Enable the OpenTelemetry diagnostic logger. Diagnostic messages are forwarded to the Platformatic global logger using the current logger level.
756
871
  */
757
872
  diagLogger?: boolean | string;
873
+ /**
874
+ * How much to trace. Omitted, everything is recorded. Either a type out of the set OpenTelemetry defines for OTEL_TRACES_SAMPLER, or a package exporting a sampler.
875
+ */
876
+ sampler?:
877
+ | {
878
+ type:
879
+ | "always_on"
880
+ | "always_off"
881
+ | "traceidratio"
882
+ | "parentbased_always_on"
883
+ | "parentbased_always_off"
884
+ | "parentbased_traceidratio";
885
+ /**
886
+ * Options for the sampler, for instance { "ratio": 0.1 } for the ratio based ones.
887
+ */
888
+ options?: {
889
+ [k: string]: unknown;
890
+ };
891
+ }
892
+ | {
893
+ package: string;
894
+ exportName?: string;
895
+ options?: {
896
+ [k: string]: unknown;
897
+ };
898
+ };
758
899
  };
759
900
  verticalScaler?: {
760
901
  enabled?: boolean;
package/lib/capability.js CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  ChildManager,
5
5
  cleanBasePath,
6
6
  createChildProcessListener,
7
+ buildServerListenerOptions,
7
8
  createServerListener,
8
9
  getServerUrl,
9
10
  importFile,
@@ -236,7 +237,28 @@ export class NextCapability extends BaseCapability {
236
237
 
237
238
  try {
238
239
  await this.childManager.inject()
239
- const childPromise = createChildProcessListener()
240
+
241
+ // Redirect the output as soon as the child is spawned. If the server fails during startup,
242
+ // nextDev never resolves and Next.js exits the thread, so waiting for it would lose the error.
243
+ const childPromise = createChildProcessListener().then(child => {
244
+ this.#child = child
245
+
246
+ // Paolo: I couldn't really reproduce this, but in some environments our child_process patch
247
+ // might not work and thus the stdio streams are not pipeable.
248
+ // Rathen than throwing an error in that case, we log a warning and continue without redirecting the output,
249
+ // as the worst thing is that the user will lose our formatted output.
250
+ //
251
+ // This should be fixable once https://github.com/nodejs/node/pull/61836 lands and it is broadly available.
252
+ if (typeof child.stdout?.pipe === 'function' && typeof child.stderr?.pipe === 'function') {
253
+ child.stdout.setEncoding('utf8')
254
+ child.stderr.setEncoding('utf8')
255
+
256
+ child.stdout.pipe(process.stdout, { end: false })
257
+ child.stderr.pipe(process.stderr, { end: false })
258
+ } else {
259
+ this.logger.warn('Unable to redirect Next.js development server output to the main process')
260
+ }
261
+ })
240
262
 
241
263
  this.#ensurePipeableStreamsInFork()
242
264
 
@@ -288,23 +310,7 @@ export class NextCapability extends BaseCapability {
288
310
  await nextDev(serverOptions, 'default', this.root)
289
311
  }
290
312
 
291
- this.#child = await childPromise
292
-
293
- // Paolo: I couldn't really reproduce this, but in some environments our child_process patch
294
- // might not work and thus the stdio streams are not pipeable.
295
- // Rathen than throwing an error in that case, we log a warning and continue without redirecting the output,
296
- // as the worst thing is that the user will lose our formatted output.
297
- //
298
- // This should be fixable once https://github.com/nodejs/node/pull/61836 lands and it is broadly available.
299
- if (typeof this.#child.stdout?.pipe === 'function' && typeof this.#child.stderr?.pipe === 'function') {
300
- this.#child.stdout.setEncoding('utf8')
301
- this.#child.stderr.setEncoding('utf8')
302
-
303
- this.#child.stdout.pipe(process.stdout, { end: false })
304
- this.#child.stderr.pipe(process.stderr, { end: false })
305
- } else {
306
- this.logger.warn('Unable to redirect Next.js development server output to the main process')
307
- }
313
+ await childPromise
308
314
  } finally {
309
315
  await this.childManager.eject()
310
316
  }
@@ -346,7 +352,7 @@ export class NextCapability extends BaseCapability {
346
352
  await this.childManager.inject()
347
353
  const { nextStart } = await importFile(resolvePath(this.#next, './dist/cli/next-start.js'))
348
354
 
349
- const { hostname, port, backlog } = this.serverConfig ?? {}
355
+ const { hostname, port } = this.serverConfig ?? {}
350
356
  const serverOptions = {
351
357
  hostname: hostname || '127.0.0.1',
352
358
  port: port || 0
@@ -357,7 +363,7 @@ export class NextCapability extends BaseCapability {
357
363
  const serverPromise = createServerListener(
358
364
  (this.isEntrypoint ? serverOptions?.port : undefined) ?? true,
359
365
  (this.isEntrypoint ? serverOptions?.hostname : undefined) ?? true,
360
- typeof backlog === 'number' ? { backlog } : {}
366
+ buildServerListenerOptions(this.serverConfig)
361
367
  )
362
368
 
363
369
  if (this.#nextVersion.major === 14 && this.#nextVersion.minor < 2) {
@@ -405,7 +411,7 @@ export class NextCapability extends BaseCapability {
405
411
  await this.childManager.inject()
406
412
  await this.childManager.register()
407
413
 
408
- const { hostname, port, backlog } = this.serverConfig ?? {}
414
+ const { hostname, port } = this.serverConfig ?? {}
409
415
  const serverOptions = {
410
416
  hostname: hostname || '127.0.0.1',
411
417
  port: port || 0
@@ -414,10 +420,11 @@ export class NextCapability extends BaseCapability {
414
420
  const serverPromise = createServerListener(
415
421
  (this.isEntrypoint ? serverOptions?.port : undefined) ?? true,
416
422
  (this.isEntrypoint ? serverOptions?.hostname : undefined) ?? true,
417
- typeof backlog === 'number' ? { backlog } : {}
423
+ buildServerListenerOptions(this.serverConfig)
418
424
  )
419
425
 
420
- let keepAliveTimeout = parseInt(process.env.KEEP_ALIVE_TIMEOUT, 10)
426
+ // The server configuration takes precedence, KEEP_ALIVE_TIMEOUT is kept as a fallback
427
+ let keepAliveTimeout = this.serverConfig?.keepAliveTimeout ?? parseInt(process.env.KEEP_ALIVE_TIMEOUT, 10)
421
428
  if (Number.isNaN(keepAliveTimeout) || !Number.isFinite(keepAliveTimeout) || keepAliveTimeout < 0) {
422
429
  keepAliveTimeout = undefined
423
430
  }
@@ -2,6 +2,7 @@ import {
2
2
  BaseCapability,
3
3
  buildListenOptions,
4
4
  errors as basicErrors,
5
+ buildServerListenerOptions,
5
6
  createServerListener,
6
7
  getServerUrl,
7
8
  importFile,
@@ -86,8 +87,12 @@ export class NextImageOptimizerCapability extends BaseCapability {
86
87
  const serverOptions = this.serverConfig
87
88
  const listenOptions = buildListenOptions(serverOptions)
88
89
 
90
+ const listenerOptions = buildServerListenerOptions(serverOptions)
91
+ if (Object.keys(listenerOptions).length > 0) {
92
+ createServerListener(false, false, listenerOptions)
93
+ }
94
+
89
95
  if (typeof serverOptions?.backlog === 'number') {
90
- createServerListener(false, false, { backlog: serverOptions.backlog })
91
96
  listenOptions.backlog = serverOptions.backlog
92
97
  }
93
98
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/next",
3
- "version": "3.74.0",
3
+ "version": "3.75.1",
4
4
  "description": "Platformatic Next.js Capability",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -19,9 +19,9 @@
19
19
  "@babel/parser": "^7.25.3",
20
20
  "@babel/traverse": "^7.25.3",
21
21
  "@babel/types": "^7.25.2",
22
- "@platformatic/basic": "3.74.0",
23
- "@platformatic/foundation": "3.74.0",
24
- "@platformatic/globals": "3.74.0",
22
+ "@platformatic/basic": "3.75.1",
23
+ "@platformatic/foundation": "3.75.1",
24
+ "@platformatic/globals": "3.75.1",
25
25
  "@platformatic/image-optimizer": "^0.2.1",
26
26
  "amaro": "^1.0.0",
27
27
  "iovalkey": "^0.4.0",
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "devDependencies": {
33
33
  "@fastify/reply-from": "^12.0.0",
34
- "@platformatic/gateway": "3.74.0",
35
- "@platformatic/service": "3.74.0",
34
+ "@platformatic/gateway": "3.75.1",
35
+ "@platformatic/service": "3.75.1",
36
36
  "@types/node": "^22.5.0",
37
37
  "@types/react": "^19.1.11",
38
38
  "@types/react-dom": "^19.1.7",
@@ -41,7 +41,7 @@
41
41
  "tstyche": "^7.0.0",
42
42
  "execa": "^9.5.1",
43
43
  "fastify": "^5.7.3",
44
- "json-schema-to-typescript": "^15.0.1",
44
+ "json-schema-to-typescript": "^16.0.0",
45
45
  "neostandard": "^0.14.0",
46
46
  "next": "^16.1.0",
47
47
  "typescript": "~6.0.3",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/next/3.74.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/next/3.75.1.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Next.js Config",
5
5
  "type": "object",
@@ -280,6 +280,16 @@
280
280
  "type": "integer",
281
281
  "description": "The maximum length of the queue of pending connections"
282
282
  },
283
+ "keepAliveTimeout": {
284
+ "type": "integer",
285
+ "minimum": 0,
286
+ "description": "The number of milliseconds of inactivity a server needs to wait for additional incoming data, after it has finished writing the last response, before a socket will be destroyed. When running behind a load balancer, set it higher than the load balancer idle timeout."
287
+ },
288
+ "headersTimeout": {
289
+ "type": "integer",
290
+ "minimum": 0,
291
+ "description": "The number of milliseconds to wait to receive the complete HTTP headers from the client. It should be greater than keepAliveTimeout."
292
+ },
283
293
  "http2": {
284
294
  "type": "boolean"
285
295
  },
@@ -1336,6 +1346,16 @@
1336
1346
  "type": "integer",
1337
1347
  "description": "The maximum length of the queue of pending connections"
1338
1348
  },
1349
+ "keepAliveTimeout": {
1350
+ "type": "integer",
1351
+ "minimum": 0,
1352
+ "description": "The number of milliseconds of inactivity a server needs to wait for additional incoming data, after it has finished writing the last response, before a socket will be destroyed. When running behind a load balancer, set it higher than the load balancer idle timeout."
1353
+ },
1354
+ "headersTimeout": {
1355
+ "type": "integer",
1356
+ "minimum": 0,
1357
+ "description": "The number of milliseconds to wait to receive the complete HTTP headers from the client. It should be greater than keepAliveTimeout."
1358
+ },
1339
1359
  "http2": {
1340
1360
  "type": "boolean"
1341
1361
  },
@@ -2580,6 +2600,56 @@
2580
2600
  }
2581
2601
  ],
2582
2602
  "description": "Enable the OpenTelemetry diagnostic logger. Diagnostic messages are forwarded to the Platformatic global logger using the current logger level."
2603
+ },
2604
+ "sampler": {
2605
+ "description": "How much to trace. Omitted, everything is recorded. Either a type out of the set OpenTelemetry defines for OTEL_TRACES_SAMPLER, or a package exporting a sampler.",
2606
+ "anyOf": [
2607
+ {
2608
+ "type": "object",
2609
+ "properties": {
2610
+ "type": {
2611
+ "type": "string",
2612
+ "enum": [
2613
+ "always_on",
2614
+ "always_off",
2615
+ "traceidratio",
2616
+ "parentbased_always_on",
2617
+ "parentbased_always_off",
2618
+ "parentbased_traceidratio"
2619
+ ]
2620
+ },
2621
+ "options": {
2622
+ "type": "object",
2623
+ "description": "Options for the sampler, for instance { \"ratio\": 0.1 } for the ratio based ones.",
2624
+ "additionalProperties": true
2625
+ }
2626
+ },
2627
+ "required": [
2628
+ "type"
2629
+ ],
2630
+ "additionalProperties": false
2631
+ },
2632
+ {
2633
+ "type": "object",
2634
+ "description": "A module exporting a sampler, or a factory which receives the options and returns one. A relative path is resolved against the application directory.",
2635
+ "properties": {
2636
+ "package": {
2637
+ "type": "string"
2638
+ },
2639
+ "exportName": {
2640
+ "type": "string"
2641
+ },
2642
+ "options": {
2643
+ "type": "object",
2644
+ "additionalProperties": true
2645
+ }
2646
+ },
2647
+ "required": [
2648
+ "package"
2649
+ ],
2650
+ "additionalProperties": false
2651
+ }
2652
+ ]
2583
2653
  }
2584
2654
  },
2585
2655
  "required": [