fastify 5.2.1 → 5.2.2

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 (73) hide show
  1. package/.vscode/settings.json +22 -0
  2. package/LICENSE +1 -1
  3. package/PROJECT_CHARTER.md +7 -7
  4. package/README.md +24 -25
  5. package/SPONSORS.md +2 -0
  6. package/docs/Guides/Benchmarking.md +4 -4
  7. package/docs/Guides/Database.md +1 -1
  8. package/docs/Guides/Delay-Accepting-Requests.md +10 -10
  9. package/docs/Guides/Ecosystem.md +5 -1
  10. package/docs/Guides/Fluent-Schema.md +1 -1
  11. package/docs/Guides/Getting-Started.md +9 -5
  12. package/docs/Guides/Index.md +1 -1
  13. package/docs/Guides/Migration-Guide-V4.md +1 -1
  14. package/docs/Guides/Migration-Guide-V5.md +12 -2
  15. package/docs/Guides/Plugins-Guide.md +6 -6
  16. package/docs/Guides/Serverless.md +14 -48
  17. package/docs/Guides/Style-Guide.md +2 -2
  18. package/docs/Guides/Testing.md +2 -2
  19. package/docs/Guides/Write-Plugin.md +2 -3
  20. package/docs/Reference/ContentTypeParser.md +58 -78
  21. package/docs/Reference/Decorators.md +50 -60
  22. package/docs/Reference/Encapsulation.md +28 -33
  23. package/docs/Reference/Errors.md +50 -53
  24. package/docs/Reference/HTTP2.md +7 -7
  25. package/docs/Reference/Hooks.md +31 -30
  26. package/docs/Reference/LTS.md +10 -15
  27. package/docs/Reference/Lifecycle.md +19 -24
  28. package/docs/Reference/Logging.md +59 -56
  29. package/docs/Reference/Middleware.md +19 -19
  30. package/docs/Reference/Plugins.md +55 -71
  31. package/docs/Reference/Principles.md +25 -30
  32. package/docs/Reference/Reply.md +11 -10
  33. package/docs/Reference/Request.md +89 -98
  34. package/docs/Reference/Routes.md +108 -128
  35. package/docs/Reference/Server.md +18 -16
  36. package/docs/Reference/Type-Providers.md +19 -21
  37. package/docs/Reference/TypeScript.md +1 -18
  38. package/docs/Reference/Validation-and-Serialization.md +134 -159
  39. package/docs/Reference/Warnings.md +22 -25
  40. package/fastify.js +1 -1
  41. package/lib/contentTypeParser.js +7 -8
  42. package/lib/error-handler.js +14 -12
  43. package/lib/headRoute.js +4 -2
  44. package/lib/pluginUtils.js +4 -2
  45. package/lib/server.js +5 -0
  46. package/lib/validation.js +1 -1
  47. package/lib/warnings.js +9 -0
  48. package/lib/wrapThenable.js +8 -1
  49. package/package.json +10 -10
  50. package/test/build/error-serializer.test.js +2 -1
  51. package/test/bundler/esbuild/package.json +1 -1
  52. package/test/close.test.js +125 -108
  53. package/test/custom-parser-async.test.js +34 -36
  54. package/test/genReqId.test.js +125 -174
  55. package/test/has-route.test.js +1 -3
  56. package/test/internals/content-type-parser.test.js +1 -1
  57. package/test/issue-4959.test.js +84 -0
  58. package/test/listen.1.test.js +37 -34
  59. package/test/listen.2.test.js +47 -40
  60. package/test/listen.3.test.js +28 -32
  61. package/test/listen.4.test.js +61 -45
  62. package/test/listen.5.test.js +23 -0
  63. package/test/register.test.js +55 -50
  64. package/test/request-error.test.js +114 -94
  65. package/test/route-shorthand.test.js +36 -32
  66. package/test/server.test.js +0 -175
  67. package/test/stream.5.test.js +35 -33
  68. package/test/throw.test.js +87 -91
  69. package/test/toolkit.js +32 -0
  70. package/test/trust-proxy.test.js +23 -23
  71. package/test/types/instance.test-d.ts +1 -0
  72. package/test/upgrade.test.js +32 -30
  73. package/types/instance.d.ts +4 -0
@@ -2,9 +2,8 @@
2
2
 
3
3
  ## Routes
4
4
 
5
- The route methods will configure the endpoints of your application. You have two
6
- ways to declare a route with Fastify: the shorthand method and the full
7
- declaration.
5
+ The route methods configure the endpoints of the application. Routes can be
6
+ declared using the shorthand method or the full declaration.
8
7
 
9
8
  - [Full declaration](#full-declaration)
10
9
  - [Routes options](#routes-options)
@@ -138,11 +137,11 @@ fastify.route(options)
138
137
 
139
138
  * `reply` is defined in [Reply](./Reply.md).
140
139
 
141
- **Notice:** The documentation of `onRequest`, `preParsing`, `preValidation`,
142
- `preHandler`, `preSerialization`, `onSend`, and `onResponse` are described in
143
- more detail in [Hooks](./Hooks.md). Additionally, to send a response before the
144
- request is handled by the `handler` please refer to [Respond to a request from a
145
- hook](./Hooks.md#respond-to-a-request-from-a-hook).
140
+ > 🛈 Note: The documentation for `onRequest`, `preParsing`, `preValidation`,
141
+ > `preHandler`, `preSerialization`, `onSend`, and `onResponse` is detailed in
142
+ > [Hooks](./Hooks.md). To send a response before the request is handled by the
143
+ > `handler`, see [Respond to a request from
144
+ > a hook](./Hooks.md#respond-to-a-request-from-a-hook).
146
145
 
147
146
  Example:
148
147
  ```js
@@ -234,17 +233,17 @@ const opts = {
234
233
  fastify.get('/', opts)
235
234
  ```
236
235
 
237
- > Note: if the handler is specified in both the `options` and as the third
238
- > parameter to the shortcut method then throws a duplicate `handler` error.
236
+ > 🛈 Note: Specifying the handler in both `options` and as the third parameter to
237
+ > the shortcut method throws a duplicate `handler` error.
239
238
 
240
239
  ### Url building
241
240
  <a id="url-building"></a>
242
241
 
243
242
  Fastify supports both static and dynamic URLs.
244
243
 
245
- To register a **parametric** path, use the *colon* before the parameter name.
246
- For **wildcard**, use the *star*. *Remember that static routes are always
247
- checked before parametric and wildcard.*
244
+ To register a **parametric** path, use a *colon* before the parameter name. For
245
+ **wildcard**, use a *star*. Static routes are always checked before parametric
246
+ and wildcard routes.
248
247
 
249
248
  ```js
250
249
  // parametric
@@ -266,9 +265,8 @@ fastify.get('/example/:userId/:secretToken', function (request, reply) {
266
265
  fastify.get('/example/*', function (request, reply) {})
267
266
  ```
268
267
 
269
- Regular expression routes are supported as well, but be aware that you have to
270
- escape slashes. Take note that RegExp is also very expensive in terms of
271
- performance!
268
+ Regular expression routes are supported, but slashes must be escaped.
269
+ Take note that RegExp is also very expensive in terms of performance!
272
270
  ```js
273
271
  // parametric with regexp
274
272
  fastify.get('/example/:file(^\\d+).png', function (request, reply) {
@@ -306,24 +304,24 @@ fastify.get('/example/at/:hour(^\\d{2})h:minute(^\\d{2})m', function (request, r
306
304
  In this case as parameter separator it is possible to use whatever character is
307
305
  not matched by the regular expression.
308
306
 
309
- The last parameter can be made optional if you add a question mark ("?") to the
310
- end of the parameters name.
307
+ The last parameter can be made optional by adding a question mark ("?") to the
308
+ end of the parameter name.
311
309
  ```js
312
310
  fastify.get('/example/posts/:id?', function (request, reply) {
313
311
  const { id } = request.params;
314
312
  // your code here
315
313
  })
316
314
  ```
317
- In this case you can request `/example/posts` as well as `/example/posts/1`.
318
- The optional param will be undefined if not specified.
315
+ In this case, `/example/posts` and `/example/posts/1` are both valid. The
316
+ optional param will be `undefined` if not specified.
319
317
 
320
- Having a route with multiple parameters may negatively affect performance, so
321
- prefer a single parameter approach whenever possible, especially on routes that
322
- are on the hot path of your application. If you are interested in how we handle
323
- the routing, check out [find-my-way](https://github.com/delvedor/find-my-way).
318
+ Having a route with multiple parameters may negatively affect performance.
319
+ Prefer a single parameter approach, especially on routes that are on the hot
320
+ path of your application. For more details, see
321
+ [find-my-way](https://github.com/delvedor/find-my-way).
324
322
 
325
- If you want a path containing a colon without declaring a parameter, use a
326
- double colon. For example:
323
+ To include a colon in a path without declaring a parameter, use a double colon.
324
+ For example:
327
325
  ```js
328
326
  fastify.post('/name::verb') // will be interpreted as /name:verb
329
327
  ```
@@ -340,12 +338,12 @@ fastify.get('/', options, async function (request, reply) {
340
338
  })
341
339
  ```
342
340
 
343
- As you can see, we are not calling `reply.send` to send back the data to the
344
- user. You just need to return the body and you are done!
341
+ As shown, `reply.send` is not called to send data back to the user. Simply
342
+ return the body and you are done!
345
343
 
346
- If you need it you can also send back the data to the user with `reply.send`. In
347
- this case do not forget to `return reply` or `await reply` in your `async`
348
- handler or you will introduce a race condition in certain situations.
344
+ If needed, you can also send data back with `reply.send`. In this case, do not
345
+ forget to `return reply` or `await reply` in your `async` handler to avoid race
346
+ conditions.
349
347
 
350
348
  ```js
351
349
  fastify.get('/', options, async function (request, reply) {
@@ -378,48 +376,42 @@ fastify.get('/', options, async function (request, reply) {
378
376
  })
379
377
  ```
380
378
 
381
- **Warning:**
382
- * When using both `return value` and `reply.send(value)` at the same time, the
383
- first one that happens takes precedence, the second value will be discarded,
384
- and a *warn* log will also be emitted because you tried to send a response
385
- twice.
386
- * Calling `reply.send()` outside of the promise is possible but requires special
387
- attention. For more details read [promise-resolution](#promise-resolution).
388
- * You cannot return `undefined`. For more details read
389
- [promise-resolution](#promise-resolution).
379
+ > ⚠ Warning:
380
+ > * When using both `return value` and `reply.send(value)`, the first one takes
381
+ > precedence, the second is discarded, and a *warn* log is emitted.
382
+ > * Calling `reply.send()` outside of the promise is possible but requires special
383
+ > attention. See [promise-resolution](#promise-resolution).
384
+ > * `undefined` cannot be returned. See [promise-resolution](#promise-resolution).
390
385
 
391
386
  ### Promise resolution
392
387
  <a id="promise-resolution"></a>
393
388
 
394
- If your handler is an `async` function or returns a promise, you should be aware
395
- of the special behavior that is necessary to support the callback and promise
396
- control-flow. When the handler's promise is resolved, the reply will be
397
- automatically sent with its value unless you explicitly await or return `reply`
398
- in your handler.
389
+ If the handler is an `async` function or returns a promise, be aware of the
390
+ special behavior to support callback and promise control-flow. When the
391
+ handler's promise resolves, the reply is automatically sent with its value
392
+ unless you explicitly await or return `reply` in the handler.
399
393
 
400
- 1. If you want to use `async/await` or promises but respond with a value with
401
- `reply.send`:
394
+ 1. If using `async/await` or promises but responding with `reply.send`:
402
395
  - **Do** `return reply` / `await reply`.
403
396
  - **Do not** forget to call `reply.send`.
404
- 2. If you want to use `async/await` or promises:
397
+ 2. If using `async/await` or promises:
405
398
  - **Do not** use `reply.send`.
406
- - **Do** return the value that you want to send.
399
+ - **Do** return the value to send.
407
400
 
408
- In this way, we can support both `callback-style` and `async-await`, with the
409
- minimum trade-off. Despite so much freedom we highly recommend going with only
410
- one style because error handling should be handled in a consistent way within
411
- your application.
401
+ This approach supports both `callback-style` and `async-await` with minimal
402
+ trade-off. However, it is recommended to use only one style for consistent
403
+ error handling within your application.
412
404
 
413
- **Notice**: Every async function returns a promise by itself.
405
+ > 🛈 Note: Every async function returns a promise by itself.
414
406
 
415
407
  ### Route Prefixing
416
408
  <a id="route-prefixing"></a>
417
409
 
418
- Sometimes you need to maintain two or more different versions of the same API; a
419
- classic approach is to prefix all the routes with the API version number,
420
- `/v1/user` for example. Fastify offers you a fast and smart way to create
421
- different versions of the same API without changing all the route names by hand,
422
- *route prefixing*. Let's see how it works:
410
+ Sometimes maintaining multiple versions of the same API is necessary. A common
411
+ approach is to prefix routes with the API version number, e.g., `/v1/user`.
412
+ Fastify offers a fast and smart way to create different versions of the same API
413
+ without changing all the route names by hand, called *route prefixing*. Here is
414
+ how it works:
423
415
 
424
416
  ```js
425
417
  // server.js
@@ -446,19 +438,18 @@ module.exports = function (fastify, opts, done) {
446
438
  done()
447
439
  }
448
440
  ```
449
- Fastify will not complain because you are using the same name for two different
450
- routes, because at compilation time it will handle the prefix automatically
451
- *(this also means that the performance will not be affected at all!)*.
441
+ Fastify will not complain about using the same name for two different routes
442
+ because it handles the prefix automatically at compilation time. This ensures
443
+ performance is not affected.
452
444
 
453
- Now your clients will have access to the following routes:
445
+ Now clients will have access to the following routes:
454
446
  - `/v1/user`
455
447
  - `/v2/user`
456
448
 
457
- You can do this as many times as you want, it also works for nested `register`,
458
- and route parameters are supported as well.
449
+ This can be done multiple times and works for nested `register`. Route
450
+ parameters are also supported.
459
451
 
460
- In case you want to use prefix for all of your routes, you can put them inside a
461
- plugin:
452
+ To use a prefix for all routes, place them inside a plugin:
462
453
 
463
454
  ```js
464
455
  const fastify = require('fastify')()
@@ -483,10 +474,8 @@ await fastify.listen({ port: 3000 })
483
474
  ### Route Prefixing and fastify-plugin
484
475
  <a id="fastify-plugin"></a>
485
476
 
486
- Be aware that if you use
487
- [`fastify-plugin`](https://github.com/fastify/fastify-plugin) for wrapping your
488
- routes, this option will not work. You can still make it work by wrapping a
489
- plugin in a plugin, e. g.:
477
+ If using [`fastify-plugin`](https://github.com/fastify/fastify-plugin) to wrap
478
+ routes, this option will not work. To make it work, wrap a plugin in a plugin:
490
479
  ```js
491
480
  const fp = require('fastify-plugin')
492
481
  const routes = require('./lib/routes')
@@ -502,27 +491,23 @@ module.exports = fp(async function (app, opts) {
502
491
 
503
492
  #### Handling of / route inside prefixed plugins
504
493
 
505
- The `/` route has different behavior depending on if the prefix ends with `/` or
506
- not. As an example, if we consider a prefix `/something/`, adding a `/` route
507
- will only match `/something/`. If we consider a prefix `/something`, adding a
508
- `/` route will match both `/something` and `/something/`.
494
+ The `/` route behaves differently based on whether the prefix ends with `/`.
495
+ For example, with a prefix `/something/`, adding a `/` route matches only
496
+ `/something/`. With a prefix `/something`, adding a `/` route matches both
497
+ `/something` and `/something/`.
509
498
 
510
499
  See the `prefixTrailingSlash` route option above to change this behavior.
511
500
 
512
501
  ### Custom Log Level
513
502
  <a id="custom-log-level"></a>
514
503
 
515
- You might need different log levels in your routes; Fastify achieves this in a
516
- very straightforward way.
504
+ Different log levels can be set for routes in Fastify by passing the `logLevel`
505
+ option to the plugin or route with the desired
506
+ [value](https://github.com/pinojs/pino/blob/master/docs/api.md#level-string).
517
507
 
518
- You just need to pass the option `logLevel` to the plugin option or the route
519
- option with the
520
- [value](https://github.com/pinojs/pino/blob/master/docs/api.md#level-string)
521
- that you need.
522
-
523
- Be aware that if you set the `logLevel` at plugin level, also the
508
+ Be aware that setting `logLevel` at the plugin level also affects
524
509
  [`setNotFoundHandler`](./Server.md#setnotfoundhandler) and
525
- [`setErrorHandler`](./Server.md#seterrorhandler) will be affected.
510
+ [`setErrorHandler`](./Server.md#seterrorhandler).
526
511
 
527
512
  ```js
528
513
  // server.js
@@ -534,22 +519,21 @@ fastify.register(require('./routes/events'), { logLevel: 'debug' })
534
519
  fastify.listen({ port: 3000 })
535
520
  ```
536
521
 
537
- Or you can directly pass it to a route:
522
+ Or pass it directly to a route:
538
523
  ```js
539
524
  fastify.get('/', { logLevel: 'warn' }, (request, reply) => {
540
525
  reply.send({ hello: 'world' })
541
526
  })
542
527
  ```
543
- *Remember that the custom log level is applied only to the routes, and not to
544
- the global Fastify Logger, accessible with `fastify.log`*
528
+ *Remember that the custom log level applies only to routes, not to the global
529
+ Fastify Logger, accessible with `fastify.log`.*
545
530
 
546
531
  ### Custom Log Serializer
547
532
  <a id="custom-log-serializer"></a>
548
533
 
549
- In some contexts, you may need to log a large object but it could be a waste of
550
- resources for some routes. In this case, you can define custom
534
+ In some contexts, logging a large object may waste resources. Define custom
551
535
  [`serializers`](https://github.com/pinojs/pino/blob/master/docs/api.md#serializers-object)
552
- and attach them in the right context!
536
+ and attach them in the appropriate context.
553
537
 
554
538
  ```js
555
539
  const fastify = require('fastify')({ logger: true })
@@ -568,7 +552,7 @@ fastify.register(require('./routes/events'), {
568
552
  fastify.listen({ port: 3000 })
569
553
  ```
570
554
 
571
- You can inherit serializers by context:
555
+ Serializers can be inherited by context:
572
556
 
573
557
  ```js
574
558
  const fastify = Fastify({
@@ -629,23 +613,22 @@ fastify.listen({ port: 3000 })
629
613
  ### Constraints
630
614
  <a id="constraints"></a>
631
615
 
632
- Fastify supports constraining routes to match only certain requests based on
633
- some property of the request, like the `Host` header, or any other value via
616
+ Fastify supports constraining routes to match certain requests based on
617
+ properties like the `Host` header or any other value via
634
618
  [`find-my-way`](https://github.com/delvedor/find-my-way) constraints.
635
619
  Constraints are specified in the `constraints` property of the route options.
636
- Fastify has two built-in constraints ready for use: the `version` constraint and
637
- the `host` constraint, and you can add your own custom constraint strategies to
638
- inspect other parts of a request to decide if a route should be executed for a
639
- request.
620
+ Fastify has two built-in constraints: `version` and `host`. Custom constraint
621
+ strategies can be added to inspect other parts of a request to decide if a route
622
+ should be executed.
640
623
 
641
624
  #### Version Constraints
642
625
 
643
626
  You can provide a `version` key in the `constraints` option to a route.
644
- Versioned routes allow you to declare multiple handlers for the same HTTP route
645
- path, which will then be matched according to each request's `Accept-Version`
646
- header. The `Accept-Version` header value should follow the
647
- [semver](https://semver.org/) specification, and routes should be declared with
648
- exact semver versions for matching.
627
+ Versioned routes allows multiple handlers to be declared for the same HTTP
628
+ route path, matched according to the request's `Accept-Version` header.
629
+ The `Accept-Version` header value should follow the
630
+ [semver](https://semver.org/) specification, and routes should be declared
631
+ with exact semver versions for matching.
649
632
 
650
633
  Fastify will require a request `Accept-Version` header to be set if the route
651
634
  has a version set, and will prefer a versioned route to a non-versioned route
@@ -676,20 +659,20 @@ fastify.inject({
676
659
  })
677
660
  ```
678
661
 
679
- > ## Security Notice
680
- > Remember to set a
662
+ > ⚠ Warning:
663
+ > Set a
681
664
  > [`Vary`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary)
682
- > header in your responses with the value you are using for defining the
683
- > versioning (e.g.: `'Accept-Version'`), to prevent cache poisoning attacks. You
684
- > can also configure this as part of your Proxy/CDN.
665
+ > header in responses with the value used for versioning
666
+ > (e.g., `'Accept-Version'`) to prevent cache poisoning attacks.
667
+ > This can also be configured in a Proxy/CDN.
685
668
  >
686
669
  > ```js
687
670
  > const append = require('vary').append
688
671
  > fastify.addHook('onSend', (req, reply, payload, done) => {
689
- > if (req.headers['accept-version']) { // or the custom header you are using
672
+ > if (req.headers['accept-version']) { // or the custom header being used
690
673
  > let value = reply.getHeader('Vary') || ''
691
674
  > const header = Array.isArray(value) ? value.join(', ') : String(value)
692
- > if ((value = append(header, 'Accept-Version'))) { // or the custom header you are using
675
+ > if ((value = append(header, 'Accept-Version'))) { // or the custom header being used
693
676
  > reply.header('Vary', value)
694
677
  > }
695
678
  > }
@@ -697,22 +680,20 @@ fastify.inject({
697
680
  > })
698
681
  > ```
699
682
 
700
- If you declare multiple versions with the same major or minor, Fastify will
683
+ If multiple versions with the same major or minor are declared, Fastify will
701
684
  always choose the highest compatible with the `Accept-Version` header value.
702
685
 
703
- If the request will not have the `Accept-Version` header, a 404 error will be
704
- returned.
686
+ If the request lacks an `Accept-Version` header, a 404 error will be returned.
705
687
 
706
- It is possible to define a custom version matching logic. This can be done
707
- through the [`constraints`](./Server.md#constraints) configuration when creating
708
- a Fastify server instance.
688
+ Custom version matching logic can be defined through the
689
+ [`constraints`](./Server.md#constraints) configuration when creating a Fastify
690
+ server instance.
709
691
 
710
692
  #### Host Constraints
711
693
 
712
- You can provide a `host` key in the `constraints` route option for to limit that
713
- route to only be matched for certain values of the request `Host` header. `host`
714
- constraint values can be specified as strings for exact matches or RegExps for
715
- arbitrary host matching.
694
+ Provide a `host` key in the `constraints` route option to limit the route to
695
+ certain values of the request `Host` header. `host` constraint values can be
696
+ specified as strings for exact matches or RegExps for arbitrary host matching.
716
697
 
717
698
  ```js
718
699
  fastify.route({
@@ -761,10 +742,9 @@ fastify.route({
761
742
 
762
743
  #### Asynchronous Custom Constraints
763
744
 
764
- Custom constraints can be provided and the `constraint` criteria can be
765
- fetched from another source such as `database`. The use of asynchronous
766
- custom constraints should be a last resort as it impacts router
767
- performance.
745
+ Custom constraints can be provided, and the `constraint` criteria can be
746
+ fetched from another source such as a database. Use asynchronous custom
747
+ constraints as a last resort, as they impact router performance.
768
748
 
769
749
  ```js
770
750
  function databaseOperation(field, done) {
@@ -791,11 +771,11 @@ const secret = {
791
771
  }
792
772
  ```
793
773
 
794
- > ## Security Notice
795
- > When using with asynchronous constraint. It is highly recommend never return error
796
- > inside the callback. If the error is not preventable, it is recommended to provide
797
- > a custom `frameworkErrors` handler to deal with it. Otherwise, you route selection
798
- > may break or expose sensitive information to attackers.
774
+ > ⚠ Warning:
775
+ > When using asynchronous constraints, avoid returning errors inside the
776
+ > callback. If errors are unavoidable, provide a custom `frameworkErrors`
777
+ > handler to manage them. Otherwise, route selection may break or expose
778
+ > sensitive information.
799
779
  >
800
780
  > ```js
801
781
  > const Fastify = require('fastify')
@@ -166,7 +166,7 @@ When set to `true`, upon [`close`](#close) the server will iterate the current
166
166
  persistent connections and [destroy their
167
167
  sockets](https://nodejs.org/dist/latest-v16.x/docs/api/net.html#socketdestroyerror).
168
168
 
169
- > **Warning**
169
+ > Warning:
170
170
  > Connections are not inspected to determine if requests have
171
171
  > been completed.
172
172
 
@@ -193,7 +193,7 @@ to understand the effect of this option. This option only applies when HTTP/1.1
193
193
  is in use. Also, when `serverFactory` option is specified, this option is
194
194
  ignored.
195
195
 
196
- > **Note**
196
+ > 🛈 Note:
197
197
  > At the time of writing, only node >= v16.10.0 supports this option.
198
198
 
199
199
  ### `requestTimeout`
@@ -211,7 +211,7 @@ It must be set to a non-zero value (e.g. 120 seconds) to protect against potenti
211
211
  Denial-of-Service attacks in case the server is deployed without a reverse proxy
212
212
  in front.
213
213
 
214
- > **Note**
214
+ > 🛈 Note:
215
215
  > At the time of writing, only node >= v14.11.0 supports this option
216
216
 
217
217
  ### `ignoreTrailingSlash`
@@ -529,7 +529,7 @@ Especially in distributed systems, you may want to override the default ID
529
529
  generation behavior as shown below. For generating `UUID`s you may want to check
530
530
  out [hyperid](https://github.com/mcollina/hyperid).
531
531
 
532
- > **Note**
532
+ > 🛈 Note:
533
533
  > `genReqId` will be not called if the header set in
534
534
  > <code>[requestIdHeader](#requestidheader)</code> is available (defaults to
535
535
  > 'request-id').
@@ -581,7 +581,7 @@ fastify.get('/', (request, reply) => {
581
581
  })
582
582
  ```
583
583
 
584
- > **Note**
584
+ > 🛈 Note:
585
585
  > If a request contains multiple `x-forwarded-host` or `x-forwarded-proto`
586
586
  > headers, it is only the last one that is used to derive `request.hostname`
587
587
  > and `request.protocol`.
@@ -599,8 +599,9 @@ controls [avvio](https://www.npmjs.com/package/avvio) 's `timeout` parameter.
599
599
  ### `querystringParser`
600
600
  <a id="factory-querystring-parser"></a>
601
601
 
602
- The default query string parser that Fastify uses is the Node.js's core
603
- `querystring` module.
602
+ The default query string parser that Fastify uses is a more performant fork
603
+ of Node.js's core `querystring` module called
604
+ [`fast-querystring`](https://github.com/anonrig/fast-querystring).
604
605
 
605
606
  You can use this option to use a custom parser, such as
606
607
  [`qs`](https://www.npmjs.com/package/qs).
@@ -619,7 +620,7 @@ You can also use Fastify's default parser but change some handling behavior,
619
620
  like the example below for case insensitive keys and values:
620
621
 
621
622
  ```js
622
- const querystring = require('node:querystring')
623
+ const querystring = require('fast-querystring')
623
624
  const fastify = require('fastify')({
624
625
  querystringParser: str => querystring.parse(str.toLowerCase())
625
626
  })
@@ -735,7 +736,7 @@ Fastify provides default error handlers for the most common use cases. It is
735
736
  possible to override one or more of those handlers with custom code using this
736
737
  option.
737
738
 
738
- > **Note**
739
+ > 🛈 Note:
739
740
  > Only `FST_ERR_BAD_URL` and `FST_ERR_ASYNC_CONSTRAINT` are implemented at present.
740
741
 
741
742
  ```js
@@ -788,7 +789,7 @@ function defaultClientErrorHandler (err, socket) {
788
789
  }
789
790
  ```
790
791
 
791
- > **Note**
792
+ > 🛈 Note:
792
793
  > `clientErrorHandler` operates with raw sockets. The handler is expected to
793
794
  > return a properly formed HTTP response that includes a status line, HTTP headers
794
795
  > and a message body. Before attempting to write the socket, the handler should
@@ -877,7 +878,7 @@ fastify.get('/dev', async (request, reply) => {
877
878
  [server](https://nodejs.org/api/http.html#http_class_http_server) object as
878
879
  returned by the [**`Fastify factory function`**](#factory).
879
880
 
880
- > **Warning**
881
+ > Warning:
881
882
  > If utilized improperly, certain Fastify features could be disrupted.
882
883
  > It is recommended to only use it for attaching listeners.
883
884
 
@@ -973,7 +974,8 @@ server.listen({
973
974
  By default, the server will listen on the address(es) resolved by `localhost`
974
975
  when no specific host is provided. If listening on any available interface is
975
976
  desired, then specifying `0.0.0.0` for the address will listen on all IPv4
976
- addresses. The following table details the possible values for `host` when
977
+ addresses. The address argument provided above will then return the first such
978
+ IPv4 address. The following table details the possible values for `host` when
977
979
  targeting `localhost`, and what the result of those values for `host` will be.
978
980
 
979
981
  Host | IPv4 | IPv6
@@ -1219,7 +1221,7 @@ different ways to define a name (in order).
1219
1221
  Newlines are replaced by ` -- `. This will help to identify the root cause when
1220
1222
  you deal with many plugins.
1221
1223
 
1222
- > **Warning**
1224
+ > Warning:
1223
1225
  > If you have to deal with nested plugins, the name differs with the usage of
1224
1226
  > the [fastify-plugin](https://github.com/fastify/fastify-plugin) because
1225
1227
  > no new scope is created and therefore we have no place to attach contextual
@@ -1355,7 +1357,7 @@ Set the schema error formatter for all routes. See
1355
1357
  Set the schema serializer compiler for all routes. See
1356
1358
  [#schema-serializer](./Validation-and-Serialization.md#schema-serializer).
1357
1359
 
1358
- > **Note**
1360
+ > 🛈 Note:
1359
1361
  > [`setReplySerializer`](#set-reply-serializer) has priority if set!
1360
1362
 
1361
1363
  #### validatorCompiler
@@ -1488,7 +1490,7 @@ lifecycle](./Lifecycle.md#lifecycle). *async-await* is supported as well.
1488
1490
  You can also register [`preValidation`](./Hooks.md#route-hooks) and
1489
1491
  [`preHandler`](./Hooks.md#route-hooks) hooks for the 404 handler.
1490
1492
 
1491
- > **Note**
1493
+ > 🛈 Note:
1492
1494
  > The `preValidation` hook registered using this method will run for a
1493
1495
  > route that Fastify does not recognize and **not** when a route handler manually
1494
1496
  > calls [`reply.callNotFound`](./Reply.md#call-not-found). In which case, only
@@ -1524,7 +1526,7 @@ plugins are registered. If you would like to augment the behavior of the default
1524
1526
  arguments `fastify.setNotFoundHandler()` within the context of these registered
1525
1527
  plugins.
1526
1528
 
1527
- > **Note**
1529
+ > 🛈 Note:
1528
1530
  > Some config properties from the request object will be
1529
1531
  > undefined inside the custom not found handler. E.g.:
1530
1532
  > `request.routerPath`, `routerMethod` and `context.config`.
@@ -2,18 +2,16 @@
2
2
 
3
3
  ## Type Providers
4
4
 
5
- Type Providers are a TypeScript only feature that enables Fastify to statically
6
- infer type information directly from inline JSON Schema. They are an alternative
7
- to specifying generic arguments on routes; and can greatly reduce the need to
8
- keep associated types for each schema defined in your project.
5
+ Type Providers are a TypeScript feature that enables Fastify to infer type
6
+ information from inline JSON Schema. They are an alternative to specifying
7
+ generic arguments on routes and can reduce the need to keep associated types for
8
+ each schema in a project.
9
9
 
10
10
  ### Providers
11
11
 
12
- Type Providers are offered as additional packages you will need to install into
13
- your project. Each provider uses a different inference library under the hood;
14
- allowing you to select the library most appropriate for your needs. Official Type
15
- Provider packages follow a `@fastify/type-provider-{provider-name}` naming
16
- convention, and there are several community ones available as well.
12
+ Official Type Provider packages follow the
13
+ `@fastify/type-provider-{provider-name}` naming convention.
14
+ Several community providers are also available.
17
15
 
18
16
  The following inference packages are supported:
19
17
 
@@ -30,7 +28,7 @@ See also the Type Provider wrapper packages for each of the packages respectivel
30
28
 
31
29
  ### Json Schema to Ts
32
30
 
33
- The following sets up a `json-schema-to-ts` Type Provider
31
+ The following sets up a `json-schema-to-ts` Type Provider:
34
32
 
35
33
  ```bash
36
34
  $ npm i @fastify/type-provider-json-schema-to-ts
@@ -62,7 +60,7 @@ server.get('/route', {
62
60
 
63
61
  ### TypeBox
64
62
 
65
- The following sets up a TypeBox Type Provider
63
+ The following sets up a TypeBox Type Provider:
66
64
 
67
65
  ```bash
68
66
  $ npm i @fastify/type-provider-typebox
@@ -89,14 +87,14 @@ server.get('/route', {
89
87
  })
90
88
  ```
91
89
 
92
- See also the [TypeBox
93
- documentation](https://github.com/sinclairzx81/typebox#validation) on how to set
94
- up AJV to work with TypeBox.
90
+ See the [TypeBox
91
+ documentation](https://github.com/sinclairzx81/typebox#validation)
92
+ for setting up AJV to work with TypeBox.
95
93
 
96
94
  ### Zod
97
95
 
98
96
  See [official documentation](https://github.com/turkerdev/fastify-type-provider-zod)
99
- for Zod type provider instructions.
97
+ for Zod Type Provider instructions.
100
98
 
101
99
 
102
100
  ### Scoped Type-Provider
@@ -154,9 +152,9 @@ fastify.register(pluginWithJsonSchema)
154
152
  fastify.register(pluginWithTypebox)
155
153
  ```
156
154
 
157
- It's also important to mention that since the types don't propagate globally,
158
- _currently_ it is not possible to avoid multiple registrations on routes when
159
- dealing with several scopes, see below:
155
+ It is important to note that since the types do not propagate globally, it is
156
+ currently not possible to avoid multiple registrations on routes when dealing
157
+ with several scopes, as shown below:
160
158
 
161
159
  ```ts
162
160
  import Fastify from 'fastify'
@@ -178,7 +176,7 @@ function plugin1(fastify: FastifyInstance, _opts, done): void {
178
176
  })
179
177
  }
180
178
  }, (req) => {
181
- // it doesn't work! in a new scope needs to call `withTypeProvider` again
179
+ // In a new scope, call `withTypeProvider` again to ensure it works
182
180
  const { x, y, z } = req.body
183
181
  });
184
182
  done()
@@ -205,8 +203,8 @@ function plugin2(fastify: FastifyInstance, _opts, done): void {
205
203
 
206
204
  ### Type Definition of FastifyInstance + TypeProvider
207
205
 
208
- When working with modules one has to make use of `FastifyInstance` with Type
209
- Provider generics. See the example below:
206
+ When working with modules, use `FastifyInstance` with Type Provider generics.
207
+ See the example below:
210
208
 
211
209
  ```ts
212
210
  // index.ts