fastify 5.9.0 → 5.11.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/PROJECT_CHARTER.md +1 -1
- package/README.md +7 -10
- package/SPONSORS.md +1 -0
- package/build/build-validation.js +2 -2
- package/docs/Guides/Delay-Accepting-Requests.md +1 -1
- package/docs/Guides/Ecosystem.md +12 -9
- package/docs/Guides/Getting-Started.md +10 -10
- package/docs/Guides/Migration-Guide-V4.md +2 -2
- package/docs/Guides/Migration-Guide-V5.md +1 -1
- package/docs/Guides/Plugins-Guide.md +1 -1
- package/docs/Guides/Prototype-Poisoning.md +3 -3
- package/docs/Guides/Serverless.md +6 -13
- package/docs/Guides/Style-Guide.md +1 -1
- package/docs/Reference/Errors.md +6 -0
- package/docs/Reference/Hooks.md +1 -1
- package/docs/Reference/Logging.md +3 -0
- package/docs/Reference/Reply.md +2 -2
- package/docs/Reference/Request.md +13 -13
- package/docs/Reference/Server.md +117 -17
- package/docs/Reference/Type-Providers.md +24 -4
- package/docs/Reference/TypeScript.md +8 -10
- package/docs/Reference/Warnings.md +5 -0
- package/eslint.config.js +1 -1
- package/fastify.d.ts +60 -13
- package/fastify.js +28 -23
- package/lib/content-type-parser.js +1 -11
- package/lib/content-type.js +70 -19
- package/lib/context.js +0 -3
- package/lib/error-handler.js +7 -26
- package/lib/errors.js +17 -0
- package/lib/four-oh-four.js +8 -10
- package/lib/handle-request.js +37 -8
- package/lib/hooks.js +5 -1
- package/lib/log-controller.js +169 -0
- package/lib/logger-factory.js +25 -4
- package/lib/reply.js +35 -44
- package/lib/req-id-gen-factory.js +4 -1
- package/lib/request.js +3 -3
- package/lib/route.js +28 -36
- package/lib/schemas.js +3 -3
- package/lib/symbols.js +1 -1
- package/lib/validation.js +10 -1
- package/lib/warnings.js +19 -1
- package/package.json +4 -4
- package/test/content-type.test.js +51 -4
- package/test/find-route.test.js +35 -0
- package/test/fix-6411.test.js +65 -0
- package/test/genReqId.test.js +24 -0
- package/test/hooks.test.js +71 -0
- package/test/internals/all.test.js +2 -1
- package/test/internals/errors.test.js +21 -1
- package/test/internals/logger.test.js +322 -0
- package/test/internals/reply.test.js +57 -4
- package/test/internals/request.test.js +10 -7
- package/test/logger/logging.test.js +40 -1
- package/test/reply-error.test.js +35 -0
- package/test/rfc-10008.test.js +147 -0
- package/test/route-shorthand.test.js +14 -4
- package/test/schema-serialization.test.js +33 -0
- package/test/stream.4.test.js +2 -2
- package/test/trust-proxy.test.js +49 -30
- package/test/types/errors.tst.ts +2 -0
- package/test/types/route.tst.ts +3 -3
- package/types/content-type-parser.d.ts +26 -6
- package/types/errors.d.ts +3 -0
- package/types/hooks.d.ts +137 -76
- package/types/instance.d.ts +152 -47
- package/types/logger.d.ts +57 -2
- package/types/plugin.d.ts +7 -3
- package/types/register.d.ts +53 -10
- package/types/reply.d.ts +62 -14
- package/types/route.d.ts +68 -34
- package/types/type-provider.d.ts +29 -8
- package/types/utils.d.ts +2 -2
package/docs/Reference/Server.md
CHANGED
|
@@ -23,6 +23,7 @@ describes the properties available in that options object.
|
|
|
23
23
|
- [`logger`](#logger)
|
|
24
24
|
- [`loggerInstance`](#loggerinstance)
|
|
25
25
|
- [`disableRequestLogging`](#disablerequestlogging)
|
|
26
|
+
- [`logController`](#logcontroller)
|
|
26
27
|
- [`serverFactory`](#serverfactory)
|
|
27
28
|
- [`requestIdHeader`](#requestidheader)
|
|
28
29
|
- [`requestIdLogLabel`](#requestidloglabel)
|
|
@@ -389,6 +390,10 @@ Pino interface by having the following methods: `info`, `error`, `debug`,
|
|
|
389
390
|
### `disableRequestLogging`
|
|
390
391
|
<a id="factory-disable-request-logging"></a>
|
|
391
392
|
|
|
393
|
+
> **Deprecated:** Use the [`logController`](#factory-log-controller)
|
|
394
|
+
> option with `disableRequestLogging` or `isLogDisabled` override instead.
|
|
395
|
+
> This top-level option will be removed in `fastify@6`.
|
|
396
|
+
|
|
392
397
|
+ Default: `false`
|
|
393
398
|
|
|
394
399
|
When logging is enabled, Fastify will issue an `info` level log
|
|
@@ -402,13 +407,25 @@ and returns a boolean. This allows for conditional request logging based on the
|
|
|
402
407
|
request properties (e.g., URL, headers, decorations).
|
|
403
408
|
|
|
404
409
|
```js
|
|
410
|
+
const { LogController } = require('fastify')
|
|
411
|
+
|
|
412
|
+
// Deprecated
|
|
405
413
|
const fastify = require('fastify')({
|
|
406
414
|
logger: true,
|
|
407
415
|
disableRequestLogging: (request) => {
|
|
408
|
-
// Disable logging for health check endpoints
|
|
409
416
|
return request.url === '/health' || request.url === '/ready'
|
|
410
417
|
}
|
|
411
418
|
})
|
|
419
|
+
|
|
420
|
+
// Recommended: use logController instead
|
|
421
|
+
const fastify = require('fastify')({
|
|
422
|
+
logger: true,
|
|
423
|
+
logController: new LogController({
|
|
424
|
+
disableRequestLogging: (request) => {
|
|
425
|
+
return request.url === '/health' || request.url === '/ready'
|
|
426
|
+
}
|
|
427
|
+
})
|
|
428
|
+
})
|
|
412
429
|
```
|
|
413
430
|
|
|
414
431
|
The other log entries that will be disabled are:
|
|
@@ -435,6 +452,86 @@ fastify.addHook('onResponse', (req, reply, done) => {
|
|
|
435
452
|
})
|
|
436
453
|
```
|
|
437
454
|
|
|
455
|
+
### `logController`
|
|
456
|
+
<a id="factory-log-controller"></a>
|
|
457
|
+
|
|
458
|
+
+ Default: `undefined`
|
|
459
|
+
|
|
460
|
+
Accepts an instance of `LogController` (or a subclass) to customize Fastify's
|
|
461
|
+
internal log lines. Extend the `LogController` class and override only the
|
|
462
|
+
methods you want to customize; all others keep their default behavior.
|
|
463
|
+
|
|
464
|
+
The `LogController` class is exported from `fastify`:
|
|
465
|
+
|
|
466
|
+
```js
|
|
467
|
+
const { LogController } = require('fastify')
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
The constructor accepts an optional options object:
|
|
471
|
+
|
|
472
|
+
| Property | Type | Default | Description |
|
|
473
|
+
|----------|------|---------|-------------|
|
|
474
|
+
| `disableRequestLogging` | `boolean \| (req) => boolean` | `false` | When `true` (or a function returning `true`), per-request log lines are suppressed. |
|
|
475
|
+
| `requestIdLogLabel` | `string` | `'reqId'` | The label used for the request identifier when logging. |
|
|
476
|
+
|
|
477
|
+
```js
|
|
478
|
+
const { LogController } = require('fastify')
|
|
479
|
+
|
|
480
|
+
class MyLogController extends LogController {
|
|
481
|
+
constructor () {
|
|
482
|
+
super({
|
|
483
|
+
requestIdLogLabel: 'traceId',
|
|
484
|
+
disableRequestLogging: (request) => {
|
|
485
|
+
return request.url === '/health'
|
|
486
|
+
}
|
|
487
|
+
})
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
incomingRequest (request, reply, metadata) {
|
|
491
|
+
// Use debug level instead of info for incoming requests
|
|
492
|
+
request.log.debug({ req: request }, 'incoming request')
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
requestCompleted (error, request, reply, metadata) {
|
|
496
|
+
// Add custom fields to the request completed log
|
|
497
|
+
if (error) {
|
|
498
|
+
reply.log.error({ res: reply, err: error, responseTime: reply.elapsedTime, customField: 'value' }, 'request errored')
|
|
499
|
+
} else {
|
|
500
|
+
reply.log.info({ res: reply, responseTime: reply.elapsedTime, customField: 'value' }, 'request completed')
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const fastify = require('fastify')({
|
|
506
|
+
logger: true,
|
|
507
|
+
logController: new MyLogController()
|
|
508
|
+
})
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
The error-related methods share a unified signature:
|
|
512
|
+
`(error, request, reply, metadata)`, where `metadata` carries any extra
|
|
513
|
+
per-method data (for example, the `statusCode` passed to `serializerError`).
|
|
514
|
+
`incomingRequest` and `routeNotFound` omit the `error` argument, since they fire
|
|
515
|
+
at lifecycle points where no error exists. `serviceUnavailable` is a further
|
|
516
|
+
exception, since no route — and therefore no `request`/`reply` — is formed.
|
|
517
|
+
|
|
518
|
+
| Method | Signature | Description |
|
|
519
|
+
|--------|-----------|-------------|
|
|
520
|
+
| `isLogDisabled` | `(request)` | Checks whether request logging is disabled for the given request. It impacts all other log methods. |
|
|
521
|
+
| `incomingRequest` | `(request, reply, metadata)` | Logs an incoming request at `info` level. |
|
|
522
|
+
| `requestCompleted` | `(error, request, reply, metadata)` | Logs the outcome of a completed request. Uses `error` level when an error is present, `info` otherwise. |
|
|
523
|
+
| `defaultErrorLog` | `(error, request, reply, metadata)` | Logs an error handled by the default error handler. Uses `error` for 5xx, `info` for 4xx. |
|
|
524
|
+
| `streamError` | `(error, request, reply, metadata)` | Logs stream-level errors after headers have been sent. |
|
|
525
|
+
| `routeNotFound` | `(request, reply, metadata)` | Logs a "route not found" message at `info` level. |
|
|
526
|
+
| `writeHeadError` | `(error, request, reply, metadata)` | Logs a warning when `writeHead` fails during error handling. |
|
|
527
|
+
| `serializerError` | `(error, request, reply, metadata)` | Logs an error when the serializer for a given status code fails. The triggering status code is available as `metadata.statusCode`. |
|
|
528
|
+
| `serviceUnavailable` | `(logger, server)` | Logs a 503 when the server is closing. Always emitted, not gated by `disableRequestLogging`. |
|
|
529
|
+
|
|
530
|
+
**Note:** When you override a method, you take full control of it — the
|
|
531
|
+
default `disableRequestLogging` check is **not** automatically applied.
|
|
532
|
+
If you need conditional logging, call `this.isLogDisabled(request)` yourself
|
|
533
|
+
or override `isLogDisabled` as well.
|
|
534
|
+
|
|
438
535
|
### `serverFactory`
|
|
439
536
|
<a id="custom-http-server"></a>
|
|
440
537
|
|
|
@@ -472,7 +569,7 @@ enhance the server instance inside the `serverFactory` function before the
|
|
|
472
569
|
### `requestIdHeader`
|
|
473
570
|
<a id="factory-request-id-header"></a>
|
|
474
571
|
|
|
475
|
-
+ Default: `
|
|
572
|
+
+ Default: `false`
|
|
476
573
|
|
|
477
574
|
The header name used to set the request-id. See [the
|
|
478
575
|
request-id](./Logging.md#logging-request-id) section.
|
|
@@ -484,8 +581,6 @@ By default `requestIdHeader` is set to `false` and will immediately use [genReqI
|
|
|
484
581
|
Setting `requestIdHeader` to an empty String (`""`) will set the
|
|
485
582
|
requestIdHeader to `false`.
|
|
486
583
|
|
|
487
|
-
+ Default: `false`
|
|
488
|
-
|
|
489
584
|
```js
|
|
490
585
|
const fastify = require('fastify')({
|
|
491
586
|
requestIdHeader: 'x-custom-id', // -> use 'X-Custom-Id' header if available
|
|
@@ -501,6 +596,10 @@ const fastify = require('fastify')({
|
|
|
501
596
|
### `requestIdLogLabel`
|
|
502
597
|
<a id="factory-request-id-log-label"></a>
|
|
503
598
|
|
|
599
|
+
> **Deprecated:** Use the [`logController`](#factory-log-controller)
|
|
600
|
+
> option with `requestIdLogLabel` instead. This top-level option will be
|
|
601
|
+
> removed in `fastify@6`.
|
|
602
|
+
|
|
504
603
|
+ Default: `'reqId'`
|
|
505
604
|
|
|
506
605
|
Defines the label used for the request identifier when logging the request.
|
|
@@ -519,9 +618,9 @@ generation behavior as shown below. For generating `UUID`s you may want to check
|
|
|
519
618
|
out [hyperid](https://github.com/mcollina/hyperid).
|
|
520
619
|
|
|
521
620
|
> ℹ️ Note:
|
|
522
|
-
> `genReqId` will be
|
|
621
|
+
> `genReqId` will not be called if the header set in
|
|
523
622
|
> <code>[requestIdHeader](#requestidheader)</code> is available (defaults to
|
|
524
|
-
>
|
|
623
|
+
> `false`).
|
|
525
624
|
|
|
526
625
|
```js
|
|
527
626
|
let i = 0
|
|
@@ -561,11 +660,11 @@ For more examples, refer to the
|
|
|
561
660
|
You may access the `ip`, `ips`, `host` and `protocol` values on the
|
|
562
661
|
[`request`](./Request.md) object.
|
|
563
662
|
|
|
564
|
-
> ⚠️ Security:
|
|
565
|
-
> These values are derived from socket/forwarding metadata and must be treated
|
|
566
|
-
> as untrusted input unless your proxy chain is explicitly trusted and
|
|
567
|
-
> validated. Do not use them directly for authorization or other
|
|
568
|
-
> security-sensitive decisions without explicit validation.
|
|
663
|
+
> ⚠️ Security:
|
|
664
|
+
> These values are derived from socket/forwarding metadata and must be treated
|
|
665
|
+
> as untrusted input unless your proxy chain is explicitly trusted and
|
|
666
|
+
> validated. Do not use them directly for authorization or other
|
|
667
|
+
> security-sensitive decisions without explicit validation.
|
|
569
668
|
|
|
570
669
|
```js
|
|
571
670
|
fastify.get('/', (request, reply) => {
|
|
@@ -853,7 +952,7 @@ function to sanitize a route's store object to use with the `prettyPrint`
|
|
|
853
952
|
functions. This function should accept a single object and return an object.
|
|
854
953
|
|
|
855
954
|
```js
|
|
856
|
-
fastify
|
|
955
|
+
const fastify = require('fastify')({
|
|
857
956
|
routerOptions: {
|
|
858
957
|
buildPrettyMeta: route => {
|
|
859
958
|
const cleanMeta = Object.assign({}, route.store)
|
|
@@ -864,7 +963,7 @@ fastify.get('/user/:username', (request, reply) => {
|
|
|
864
963
|
})
|
|
865
964
|
|
|
866
965
|
return cleanMeta // this will show up in the pretty print output!
|
|
867
|
-
}
|
|
966
|
+
}
|
|
868
967
|
}
|
|
869
968
|
})
|
|
870
969
|
```
|
|
@@ -1068,8 +1167,9 @@ objects and do not provide Fastify's decorated helpers.
|
|
|
1068
1167
|
### `querystringParser`
|
|
1069
1168
|
<a id="querystringparser"></a>
|
|
1070
1169
|
|
|
1071
|
-
The default query string parser that Fastify uses is
|
|
1072
|
-
`querystring` module
|
|
1170
|
+
The default query string parser that Fastify uses is a more performant fork
|
|
1171
|
+
of Node.js's core `querystring` module called
|
|
1172
|
+
[`fast-querystring`](https://github.com/anonrig/fast-querystring).
|
|
1073
1173
|
|
|
1074
1174
|
You can use this option to use a custom parser, such as
|
|
1075
1175
|
[`qs`](https://www.npmjs.com/package/qs).
|
|
@@ -1090,7 +1190,7 @@ You can also use Fastify's default parser but change some handling behavior,
|
|
|
1090
1190
|
like the example below for case insensitive keys and values:
|
|
1091
1191
|
|
|
1092
1192
|
```js
|
|
1093
|
-
const querystring = require('
|
|
1193
|
+
const querystring = require('fast-querystring')
|
|
1094
1194
|
const fastify = require('fastify')({
|
|
1095
1195
|
routerOptions: {
|
|
1096
1196
|
querystringParser: str => querystring.parse(str.toLowerCase())
|
|
@@ -1603,7 +1703,7 @@ Fake HTTP injection (for testing purposes)
|
|
|
1603
1703
|
<a id="addHttpMethod"></a>
|
|
1604
1704
|
|
|
1605
1705
|
Fastify supports the `GET`, `HEAD`, `TRACE`, `DELETE`, `OPTIONS`,
|
|
1606
|
-
`PATCH`, `PUT` and `
|
|
1706
|
+
`PATCH`, `PUT`, `POST` and `QUERY` HTTP methods by default.
|
|
1607
1707
|
The `addHttpMethod` method allows to add any non standard HTTP
|
|
1608
1708
|
methods to the server that are [supported by Node.js](https://nodejs.org/api/http.html#httpmethods).
|
|
1609
1709
|
|
|
@@ -34,10 +34,10 @@ $ npm i @fastify/type-provider-json-schema-to-ts
|
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
|
-
import
|
|
37
|
+
import Fastify from 'fastify'
|
|
38
38
|
import { JsonSchemaToTsProvider } from '@fastify/type-provider-json-schema-to-ts'
|
|
39
39
|
|
|
40
|
-
const server =
|
|
40
|
+
const server = Fastify().withTypeProvider<JsonSchemaToTsProvider>()
|
|
41
41
|
|
|
42
42
|
server.get('/route', {
|
|
43
43
|
schema: {
|
|
@@ -57,6 +57,26 @@ server.get('/route', {
|
|
|
57
57
|
})
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
When using raw JSON Schema objects with `JsonSchemaToTsProvider`, TypeScript
|
|
61
|
+
must be able to see the exact literal values in the schema. Inline schemas, like
|
|
62
|
+
the example above, are inferred from the route call. If the schema is moved into
|
|
63
|
+
a separate variable, use `as const`:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const querystringSchema = {
|
|
67
|
+
type: 'object',
|
|
68
|
+
properties: {
|
|
69
|
+
foo: { type: 'number' },
|
|
70
|
+
bar: { type: 'string' },
|
|
71
|
+
},
|
|
72
|
+
required: ['foo', 'bar']
|
|
73
|
+
} as const
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Without `as const`, TypeScript may widen schema values such as `type: 'object'`
|
|
77
|
+
to `type: string`, which prevents `json-schema-to-ts` from inferring the route
|
|
78
|
+
types. This assertion has no effect on the schema used by Fastify at runtime.
|
|
79
|
+
|
|
60
80
|
### TypeBox
|
|
61
81
|
|
|
62
82
|
The following sets up a TypeBox Type Provider:
|
|
@@ -66,11 +86,11 @@ $ npm i typebox @fastify/type-provider-typebox
|
|
|
66
86
|
```
|
|
67
87
|
|
|
68
88
|
```typescript
|
|
69
|
-
import
|
|
89
|
+
import Fastify from 'fastify'
|
|
70
90
|
import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'
|
|
71
91
|
import { Type } from 'typebox'
|
|
72
92
|
|
|
73
|
-
const server =
|
|
93
|
+
const server = Fastify().withTypeProvider<TypeBoxTypeProvider>()
|
|
74
94
|
|
|
75
95
|
server.get('/route', {
|
|
76
96
|
schema: {
|
|
@@ -15,7 +15,7 @@ fill in the gaps. Just make sure to read our
|
|
|
15
15
|
[`CONTRIBUTING.md`](https://github.com/fastify/fastify/blob/main/CONTRIBUTING.md)
|
|
16
16
|
file before getting started to make sure things go smoothly!
|
|
17
17
|
|
|
18
|
-
> The documentation in this section covers Fastify
|
|
18
|
+
> The documentation in this section covers Fastify typings
|
|
19
19
|
|
|
20
20
|
> Plugins may or may not include typings. See [Plugins](#plugins) for more
|
|
21
21
|
> information. We encourage users to send pull requests to improve typings
|
|
@@ -90,7 +90,7 @@ in a blank http Fastify server.
|
|
|
90
90
|
🏓
|
|
91
91
|
|
|
92
92
|
🎉 You now have a working Typescript Fastify server! This example demonstrates
|
|
93
|
-
the simplicity of the
|
|
93
|
+
the simplicity of the type system. By default, the type system
|
|
94
94
|
assumes you are using an `http` server. The later examples will demonstrate how
|
|
95
95
|
to create more complex servers such as `https` and `http2`, how to specify route
|
|
96
96
|
schemas, and more!
|
|
@@ -545,9 +545,9 @@ Fastify Plugin in a TypeScript Project.
|
|
|
545
545
|
}
|
|
546
546
|
|
|
547
547
|
// export plugin using fastify-plugin
|
|
548
|
-
export default fp(myPluginCallback
|
|
548
|
+
export default fp(myPluginCallback)
|
|
549
549
|
// or
|
|
550
|
-
// export default fp(myPluginAsync
|
|
550
|
+
// export default fp(myPluginAsync)
|
|
551
551
|
```
|
|
552
552
|
6. Run `npm run build` to compile the plugin code and produce both a JavaScript
|
|
553
553
|
source file and a type definition file.
|
|
@@ -595,7 +595,6 @@ your plugin.
|
|
|
595
595
|
}
|
|
596
596
|
|
|
597
597
|
module.exports = fp(myPlugin, {
|
|
598
|
-
fastify: '5.x',
|
|
599
598
|
name: 'my-plugin' // this is used by fastify-plugin to derive the property name
|
|
600
599
|
})
|
|
601
600
|
```
|
|
@@ -658,8 +657,8 @@ unfortunate limitation of using TypeScript and is unavoidable as of right now.
|
|
|
658
657
|
|
|
659
658
|
However, there are a couple of suggestions to help improve this experience:
|
|
660
659
|
- Make sure the `no-unused-vars` rule is enabled in
|
|
661
|
-
[ESLint](https://eslint.org/docs/rules/no-unused-vars) and any
|
|
662
|
-
are actually being loaded.
|
|
660
|
+
[ESLint](https://eslint.org/docs/latest/rules/no-unused-vars) and any
|
|
661
|
+
imported plugin are actually being loaded.
|
|
663
662
|
- Use a module such as [depcheck](https://www.npmjs.com/package/depcheck) or
|
|
664
663
|
[npm-check](https://www.npmjs.com/package/npm-check) to verify plugin
|
|
665
664
|
dependencies are being used somewhere in your project.
|
|
@@ -828,7 +827,7 @@ fastify.addHook('preHandler', async (req, reply) => {
|
|
|
828
827
|
## Code Completion In Vanilla JavaScript
|
|
829
828
|
|
|
830
829
|
Vanilla JavaScript can use the published types to provide code completion (e.g.
|
|
831
|
-
[Intellisense](https://code.visualstudio.com/docs/
|
|
830
|
+
[Intellisense](https://code.visualstudio.com/docs/editing/intellisense)) by
|
|
832
831
|
following the [TypeScript JSDoc
|
|
833
832
|
Reference](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html).
|
|
834
833
|
|
|
@@ -843,8 +842,7 @@ module.exports = async function (fastify, { optionA, optionB }) {
|
|
|
843
842
|
|
|
844
843
|
## API Type System Documentation
|
|
845
844
|
|
|
846
|
-
This section is a detailed account of all the types available to you in Fastify
|
|
847
|
-
version 3.x
|
|
845
|
+
This section is a detailed account of all the types available to you in Fastify.
|
|
848
846
|
|
|
849
847
|
All `http`, `https`, and `http2` types are inferred from `@types/node`
|
|
850
848
|
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
- [FSTWRN004](#FSTWRN004)
|
|
11
11
|
- [Fastify Deprecation Codes](#fastify-deprecation-codes)
|
|
12
12
|
- [FSTDEP022](#FSTDEP022)
|
|
13
|
+
- [FSTDEP023](#FSTDEP023)
|
|
14
|
+
- [FSTDEP024](#FSTDEP024)
|
|
13
15
|
|
|
14
16
|
## Warnings
|
|
15
17
|
|
|
@@ -31,6 +33,7 @@ one of the following methods:
|
|
|
31
33
|
- Set the `NODE_NO_WARNINGS` environment variable to `1`
|
|
32
34
|
- Pass the `--no-warnings` flag to the node process
|
|
33
35
|
- Set `no-warnings` in the `NODE_OPTIONS` environment variable
|
|
36
|
+
- Pass `--disable-warning=FSTWRN004` to disable a specific warning
|
|
34
37
|
|
|
35
38
|
For more information on disabling warnings, see [Node's documentation](https://nodejs.org/api/cli.html).
|
|
36
39
|
|
|
@@ -57,3 +60,5 @@ Deprecation codes are supported by the Node.js CLI options:
|
|
|
57
60
|
| Code | Description | How to solve | Discussion |
|
|
58
61
|
| ---- | ----------- | ------------ | ---------- |
|
|
59
62
|
| <a id="FSTDEP022">FSTDEP022</a> | You are trying to access the deprecated router options on top option properties. | Use `options.routerOptions`. | [#5985](https://github.com/fastify/fastify/pull/5985)
|
|
63
|
+
| <a id="FSTDEP023">FSTDEP023</a> | `disableRequestLogging` top-level option is deprecated. | Pass a `LogController` instance via the `logController` option with `disableRequestLogging` in its constructor instead. |
|
|
64
|
+
| <a id="FSTDEP024">FSTDEP024</a> | `requestIdLogLabel` top-level option is deprecated. | Pass a `LogController` instance via the `logController` option with `requestIdLogLabel` in its constructor instead. |
|
package/eslint.config.js
CHANGED
package/fastify.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { FastifyInstance, FastifyListenOptions, PrintRoutesOptions } from './typ
|
|
|
17
17
|
import {
|
|
18
18
|
FastifyBaseLogger,
|
|
19
19
|
FastifyChildLoggerFactory,
|
|
20
|
+
LogController as LogControllerClass,
|
|
20
21
|
FastifyLogFn,
|
|
21
22
|
FastifyLoggerInstance,
|
|
22
23
|
FastifyLoggerOptions,
|
|
@@ -44,6 +45,7 @@ type Fastify = typeof fastify
|
|
|
44
45
|
|
|
45
46
|
declare namespace fastify {
|
|
46
47
|
export const errorCodes: FastifyErrorCodes
|
|
48
|
+
export { LogControllerClass as LogController }
|
|
47
49
|
|
|
48
50
|
export type FastifyHttp2SecureOptions<
|
|
49
51
|
Server extends http2.Http2SecureServer,
|
|
@@ -76,7 +78,9 @@ declare namespace fastify {
|
|
|
76
78
|
http?: http.ServerOptions | null
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
type FindMyWayVersion<RawServer extends RawServerBase> = RawServer extends http.Server
|
|
81
|
+
type FindMyWayVersion<RawServer extends RawServerBase> = RawServer extends http.Server
|
|
82
|
+
? HTTPVersion.V1
|
|
83
|
+
: HTTPVersion.V2
|
|
80
84
|
type FindMyWayConfigForServer<RawServer extends RawServerBase> = FindMyWayConfig<FindMyWayVersion<RawServer>>
|
|
81
85
|
|
|
82
86
|
export interface ConnectionError extends Error {
|
|
@@ -126,7 +130,9 @@ declare namespace fastify {
|
|
|
126
130
|
bodyLimit?: number,
|
|
127
131
|
handlerTimeout?: number,
|
|
128
132
|
maxParamLength?: number,
|
|
133
|
+
/** @deprecated Use the `logController` option with `disableRequestLogging` or `isLogDisabled` override instead. Will be removed in `fastify@6`. */
|
|
129
134
|
disableRequestLogging?: boolean | ((req: FastifyRequest) => boolean),
|
|
135
|
+
logController?: LogControllerClass,
|
|
130
136
|
exposeHeadRoutes?: boolean,
|
|
131
137
|
onProtoPoisoning?: ProtoAction,
|
|
132
138
|
onConstructorPoisoning?: ConstructorAction,
|
|
@@ -137,6 +143,7 @@ declare namespace fastify {
|
|
|
137
143
|
caseSensitive?: boolean,
|
|
138
144
|
allowUnsafeRegex?: boolean,
|
|
139
145
|
requestIdHeader?: string | false,
|
|
146
|
+
/** @deprecated Use the `logController` option with `requestIdLogLabel` instead. Will be removed in `fastify@6`. */
|
|
140
147
|
requestIdLogLabel?: string;
|
|
141
148
|
useSemicolonDelimiter?: boolean,
|
|
142
149
|
genReqId?: (req: RawRequestDefaultExpression<RawServer>) => string,
|
|
@@ -158,15 +165,39 @@ declare namespace fastify {
|
|
|
158
165
|
};
|
|
159
166
|
return503OnClosing?: boolean,
|
|
160
167
|
ajv?: Parameters<BuildCompilerFromPool>[1],
|
|
161
|
-
frameworkErrors?: <
|
|
168
|
+
frameworkErrors?: <
|
|
169
|
+
RequestGeneric extends RequestGenericInterface = RequestGenericInterface,
|
|
170
|
+
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
171
|
+
SchemaCompiler extends FastifySchema = FastifySchema
|
|
172
|
+
>(
|
|
162
173
|
error: FastifyError,
|
|
163
|
-
req: FastifyRequest<
|
|
164
|
-
|
|
174
|
+
req: FastifyRequest<
|
|
175
|
+
RequestGeneric,
|
|
176
|
+
RawServer,
|
|
177
|
+
RawRequestDefaultExpression<RawServer>,
|
|
178
|
+
FastifySchema,
|
|
179
|
+
TypeProvider
|
|
180
|
+
>,
|
|
181
|
+
res: FastifyReply<
|
|
182
|
+
RequestGeneric,
|
|
183
|
+
RawServer,
|
|
184
|
+
RawRequestDefaultExpression<RawServer>,
|
|
185
|
+
RawReplyDefaultExpression<RawServer>,
|
|
186
|
+
FastifyContextConfig,
|
|
187
|
+
SchemaCompiler,
|
|
188
|
+
TypeProvider
|
|
189
|
+
>
|
|
165
190
|
) => void,
|
|
166
191
|
rewriteUrl?: (
|
|
167
192
|
// The RawRequestDefaultExpression, RawReplyDefaultExpression, and FastifyTypeProviderDefault parameters
|
|
168
193
|
// should be narrowed further but those generic parameters are not passed to this FastifyServerOptions type
|
|
169
|
-
this: FastifyInstance<
|
|
194
|
+
this: FastifyInstance<
|
|
195
|
+
RawServer,
|
|
196
|
+
RawRequestDefaultExpression<RawServer>,
|
|
197
|
+
RawReplyDefaultExpression<RawServer>,
|
|
198
|
+
Logger,
|
|
199
|
+
FastifyTypeProviderDefault
|
|
200
|
+
>,
|
|
170
201
|
req: RawRequestDefaultExpression<RawServer>
|
|
171
202
|
) => string,
|
|
172
203
|
schemaErrorFormatter?: SchemaErrorFormatter,
|
|
@@ -193,13 +224,25 @@ declare namespace fastify {
|
|
|
193
224
|
FastifyListenOptions, FastifyInstance, PrintRoutesOptions, // './types/instance'
|
|
194
225
|
FastifyLoggerOptions, FastifyBaseLogger, FastifyLoggerInstance, FastifyLogFn, LogLevel, // './types/logger'
|
|
195
226
|
FastifyRequestContext, FastifyContextConfig, FastifyReplyContext, // './types/context'
|
|
196
|
-
RouteHandler, RouteHandlerMethod, RouteOptions, RouteShorthandMethod, RouteShorthandOptions,
|
|
227
|
+
RouteHandler, RouteHandlerMethod, RouteOptions, RouteShorthandMethod, RouteShorthandOptions,
|
|
228
|
+
RouteShorthandOptionsWithHandler, RouteGenericInterface, // './types/route'
|
|
197
229
|
FastifyRegister, FastifyRegisterOptions, RegisterOptions, // './types/register'
|
|
198
|
-
FastifyBodyParser, FastifyContentTypeParser, AddContentTypeParser, hasContentTypeParser, getDefaultJsonParser,
|
|
230
|
+
FastifyBodyParser, FastifyContentTypeParser, AddContentTypeParser, hasContentTypeParser, getDefaultJsonParser,
|
|
231
|
+
ProtoAction, ConstructorAction, // './types/content-type-parser'
|
|
199
232
|
FastifyError, // '@fastify/error'
|
|
200
233
|
FastifySchema, FastifySchemaValidationError, FastifySchemaCompiler, FastifySerializerCompiler, // './types/schema'
|
|
201
|
-
HTTPMethods, RawServerBase, RawRequestDefaultExpression, RawReplyDefaultExpression, RawServerDefault,
|
|
202
|
-
|
|
234
|
+
HTTPMethods, RawServerBase, RawRequestDefaultExpression, RawReplyDefaultExpression, RawServerDefault,
|
|
235
|
+
ContextConfigDefault, RequestBodyDefault, RequestQuerystringDefault, RequestParamsDefault, RequestHeadersDefault,
|
|
236
|
+
// './types/utils'
|
|
237
|
+
DoneFuncWithErrOrRes, HookHandlerDoneFunction, RequestPayload, onCloseAsyncHookHandler, onCloseHookHandler,
|
|
238
|
+
onErrorAsyncHookHandler, onErrorHookHandler, onReadyAsyncHookHandler, onReadyHookHandler,
|
|
239
|
+
onListenAsyncHookHandler, onListenHookHandler, onRegisterHookHandler, onRequestAsyncHookHandler,
|
|
240
|
+
onRequestHookHandler, onResponseAsyncHookHandler, onResponseHookHandler, onRouteHookHandler,
|
|
241
|
+
onSendAsyncHookHandler, onSendHookHandler, onTimeoutAsyncHookHandler, onTimeoutHookHandler,
|
|
242
|
+
preHandlerAsyncHookHandler, preHandlerHookHandler, preParsingAsyncHookHandler, preParsingHookHandler,
|
|
243
|
+
preSerializationAsyncHookHandler, preSerializationHookHandler, preValidationAsyncHookHandler,
|
|
244
|
+
preValidationHookHandler, onRequestAbortHookHandler, onRequestAbortAsyncHookHandler, preCloseAsyncHookHandler,
|
|
245
|
+
preCloseHookHandler, // './types/hooks'
|
|
203
246
|
FastifyServerFactory, FastifyServerFactoryHandler, // './types/serverFactory'
|
|
204
247
|
FastifyTypeProvider, FastifyTypeProviderDefault, SafePromiseLike, // './types/type-provider'
|
|
205
248
|
FastifyErrorCodes // './types/errors'
|
|
@@ -227,7 +270,8 @@ declare function fastify<
|
|
|
227
270
|
Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,
|
|
228
271
|
Logger extends FastifyBaseLogger = FastifyBaseLogger,
|
|
229
272
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault
|
|
230
|
-
> (opts: fastify.FastifyHttp2SecureOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger,
|
|
273
|
+
> (opts: fastify.FastifyHttp2SecureOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger,
|
|
274
|
+
TypeProvider> & SafePromiseLike<FastifyInstance<Server, Request, Reply, Logger, TypeProvider>>
|
|
231
275
|
|
|
232
276
|
declare function fastify<
|
|
233
277
|
Server extends http2.Http2Server,
|
|
@@ -235,7 +279,8 @@ declare function fastify<
|
|
|
235
279
|
Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,
|
|
236
280
|
Logger extends FastifyBaseLogger = FastifyBaseLogger,
|
|
237
281
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault
|
|
238
|
-
> (opts: fastify.FastifyHttp2Options<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger,
|
|
282
|
+
> (opts: fastify.FastifyHttp2Options<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger,
|
|
283
|
+
TypeProvider> & SafePromiseLike<FastifyInstance<Server, Request, Reply, Logger, TypeProvider>>
|
|
239
284
|
|
|
240
285
|
declare function fastify<
|
|
241
286
|
Server extends https.Server,
|
|
@@ -243,7 +288,8 @@ declare function fastify<
|
|
|
243
288
|
Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,
|
|
244
289
|
Logger extends FastifyBaseLogger = FastifyBaseLogger,
|
|
245
290
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault
|
|
246
|
-
> (opts: fastify.FastifyHttpsOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger,
|
|
291
|
+
> (opts: fastify.FastifyHttpsOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger,
|
|
292
|
+
TypeProvider> & SafePromiseLike<FastifyInstance<Server, Request, Reply, Logger, TypeProvider>>
|
|
247
293
|
|
|
248
294
|
declare function fastify<
|
|
249
295
|
Server extends http.Server,
|
|
@@ -251,7 +297,8 @@ declare function fastify<
|
|
|
251
297
|
Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,
|
|
252
298
|
Logger extends FastifyBaseLogger = FastifyBaseLogger,
|
|
253
299
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault
|
|
254
|
-
> (opts?: fastify.FastifyHttpOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger,
|
|
300
|
+
> (opts?: fastify.FastifyHttpOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger,
|
|
301
|
+
TypeProvider> & SafePromiseLike<FastifyInstance<Server, Request, Reply, Logger, TypeProvider>>
|
|
255
302
|
|
|
256
303
|
// CJS export
|
|
257
304
|
// const fastify = require('fastify')
|