fastify 5.2.0 → 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 (83) hide show
  1. package/LICENSE +1 -1
  2. package/PROJECT_CHARTER.md +7 -7
  3. package/README.md +65 -67
  4. package/SPONSORS.md +2 -0
  5. package/build/build-validation.js +1 -1
  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 +52 -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 -99
  34. package/docs/Reference/Routes.md +108 -128
  35. package/docs/Reference/Server.md +19 -17
  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/errors.js +4 -0
  44. package/lib/headRoute.js +4 -2
  45. package/lib/pluginUtils.js +4 -2
  46. package/lib/reply.js +4 -0
  47. package/lib/request.js +13 -9
  48. package/lib/server.js +5 -0
  49. package/lib/validation.js +1 -1
  50. package/lib/warnings.js +9 -0
  51. package/lib/wrapThenable.js +8 -1
  52. package/package.json +28 -17
  53. package/test/build/error-serializer.test.js +2 -1
  54. package/test/bundler/esbuild/package.json +1 -1
  55. package/test/close.test.js +125 -108
  56. package/test/custom-parser-async.test.js +34 -36
  57. package/test/custom-parser.2.test.js +19 -20
  58. package/test/custom-parser.3.test.js +56 -45
  59. package/test/delete.test.js +79 -67
  60. package/test/genReqId.test.js +125 -174
  61. package/test/has-route.test.js +1 -3
  62. package/test/internals/content-type-parser.test.js +1 -1
  63. package/test/internals/errors.test.js +19 -7
  64. package/test/issue-4959.test.js +84 -0
  65. package/test/listen.1.test.js +37 -34
  66. package/test/listen.2.test.js +47 -40
  67. package/test/listen.3.test.js +28 -32
  68. package/test/listen.4.test.js +61 -45
  69. package/test/listen.5.test.js +23 -0
  70. package/test/nullable-validation.test.js +30 -27
  71. package/test/register.test.js +55 -50
  72. package/test/request-error.test.js +114 -94
  73. package/test/route-shorthand.test.js +36 -32
  74. package/test/server.test.js +0 -175
  75. package/test/stream.5.test.js +35 -33
  76. package/test/throw.test.js +87 -91
  77. package/test/toolkit.js +32 -0
  78. package/test/trust-proxy.test.js +23 -23
  79. package/test/types/instance.test-d.ts +1 -0
  80. package/test/upgrade.test.js +32 -30
  81. package/test/web-api.test.js +44 -0
  82. package/types/instance.d.ts +4 -0
  83. package/test/test-reporter.mjs +0 -68
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2016-2024 The Fastify Team
3
+ Copyright (c) 2016-2025 The Fastify Team
4
4
 
5
5
  The Fastify team members are listed at https://github.com/fastify/fastify#team
6
6
  and in the README file.
@@ -1,6 +1,6 @@
1
1
  # Fastify Charter
2
2
 
3
- The Fastify project aims to build a fast and low overhead web framework for
3
+ The Fastify project aims to build a fast and low-overhead web framework for
4
4
  Node.js.
5
5
 
6
6
 
@@ -20,7 +20,7 @@ experience with the least overhead and a plugin architecture.
20
20
  ### 1.1: In-scope
21
21
 
22
22
  + Develop a web framework for Node.js with a focus on developer experience,
23
- performance and extensibility.
23
+ performance, and extensibility.
24
24
  + Plugin Architecture
25
25
  + Support web protocols
26
26
  + Official plugins for common user requirements
@@ -43,7 +43,7 @@ experience with the least overhead and a plugin architecture.
43
43
 
44
44
  + Support versions of Node.js at EOL (end of life) stage
45
45
  + Support serverless architecture
46
- + Contributions that violates the [Code of Conduct](CODE_OF_CONDUCT.md)
46
+ + Contributions that violate the [Code of Conduct](CODE_OF_CONDUCT.md)
47
47
 
48
48
 
49
49
  ## Section 2: Relationship with OpenJS Foundation CPC.
@@ -58,10 +58,10 @@ the Board of Directors (the "Board").
58
58
  This Fastify Charter reflects a carefully constructed balanced role for the
59
59
  Collaborators and the CPC in the governance of the OpenJS Foundation. The
60
60
  charter amendment process is for the Fastify Collaborators to propose change
61
- using simple majority of the full Fastify Organization, the proposed changes
61
+ using a majority of the full Fastify Organization, the proposed changes
62
62
  being subject to review and approval by the CPC. The CPC may additionally make
63
63
  amendments to the Collaborators charter at any time, though the CPC will not
64
- interfere with day-to-day discussions, votes or meetings of the Fastify
64
+ interfere with day-to-day discussions, votes, or meetings of the Fastify
65
65
  Organization.
66
66
 
67
67
 
@@ -92,7 +92,7 @@ Section Intentionally Left Blank
92
92
  Fastify's features can be discussed in GitHub issues and/or projects. Consensus
93
93
  on a discussion is reached when there is no objection by any collaborators.
94
94
 
95
- Whenever there is not consensus, Lead Maintainers will have final say on the
95
+ When there is no consensus, Lead Maintainers will have the final say on the
96
96
  topic.
97
97
 
98
98
  **Voting, and/or Elections**
@@ -112,7 +112,7 @@ Section Intentionally Left Blank
112
112
  Foundation Board.
113
113
 
114
114
  + *Collaborators*: contribute code and other artifacts, have the right to commit
115
- to the code base and release plugins projects. Collaborators follow the
115
+ to the code base, and release plugin projects. Collaborators follow the
116
116
  [CONTRIBUTING](CONTRIBUTING.md) guidelines to manage the project. A
117
117
  Collaborator could be encumbered by other Fastify Collaborators and never by
118
118
  the CPC or OpenJS Foundation Board.
package/README.md CHANGED
@@ -11,9 +11,9 @@
11
11
 
12
12
  [![CI](https://github.com/fastify/fastify/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify/actions/workflows/ci.yml)
13
13
  [![Package Manager
14
- CI](https://github.com/fastify/fastify/workflows/package-manager-ci/badge.svg?branch=main)](https://github.com/fastify/fastify/actions/workflows/package-manager-ci.yml)
14
+ CI](https://github.com/fastify/fastify/actions/workflows/package-manager-ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify/actions/workflows/package-manager-ci.yml)
15
15
  [![Web
16
- SIte](https://github.com/fastify/fastify/workflows/website/badge.svg?branch=main)](https://github.com/fastify/fastify/actions/workflows/website.yml)
16
+ site](https://github.com/fastify/fastify/actions/workflows/website.yml/badge.svg?branch=main)](https://github.com/fastify/fastify/actions/workflows/website.yml)
17
17
  [![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
18
18
  [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/7585/badge)](https://bestpractices.coreinfrastructure.org/projects/7585)
19
19
 
@@ -35,10 +35,10 @@ Disclosure](https://img.shields.io/badge/Security-Responsible%20Disclosure-yello
35
35
 
36
36
  <br />
37
37
 
38
- An efficient server implies a lower cost of the infrastructure, a better
39
- responsiveness under load and happy users. How can you efficiently handle the
38
+ An efficient server implies a lower cost of the infrastructure, better
39
+ responsiveness under load, and happy users. How can you efficiently handle the
40
40
  resources of your server, knowing that you are serving the highest number of
41
- requests as possible, without sacrificing security validations and handy
41
+ requests possible, without sacrificing security validations and handy
42
42
  development?
43
43
 
44
44
  Enter Fastify. Fastify is a web framework highly focused on providing the best
@@ -46,7 +46,7 @@ developer experience with the least overhead and a powerful plugin architecture.
46
46
  It is inspired by Hapi and Express and as far as we know, it is one of the
47
47
  fastest web frameworks in town.
48
48
 
49
- The `main` branch refers to the Fastify `v5` release, which is not released/LTS yet.
49
+ The `main` branch refers to the Fastify `v5` release.
50
50
  Check out the [`4.x` branch](https://github.com/fastify/fastify/tree/4.x) for `v4`.
51
51
 
52
52
  ### Table of Contents
@@ -138,7 +138,7 @@ fastify.listen({ port: 3000 }, (err, address) => {
138
138
  })
139
139
  ```
140
140
 
141
- with async-await:
141
+ With async-await:
142
142
 
143
143
  ```js
144
144
  // ESM
@@ -165,13 +165,14 @@ fastify.listen({ port: 3000 }, (err, address) => {
165
165
 
166
166
  Do you want to know more? Head to the <a
167
167
  href="./docs/Guides/Getting-Started.md"><code><b>Getting Started</b></code></a>.
168
+ If you learn best by reading code, explore the official [demo](https://github.com/fastify/demo).
168
169
 
169
170
  > ## Note
170
171
  > `.listen` binds to the local host, `localhost`, interface by default
171
172
  > (`127.0.0.1` or `::1`, depending on the operating system configuration). If
172
173
  > you are running Fastify in a container (Docker,
173
174
  > [GCP](https://cloud.google.com/), etc.), you may need to bind to `0.0.0.0`. Be
174
- > careful when deciding to listen on all interfaces; it comes with inherent
175
+ > careful when listening on all interfaces; it comes with inherent
175
176
  > [security
176
177
  > risks](https://web.archive.org/web/20170711105010/https://snyk.io/blog/mongodb-hack-and-secure-defaults/).
177
178
  > See [the documentation](./docs/Reference/Server.md#listen) for more
@@ -182,16 +183,16 @@ href="./docs/Guides/Getting-Started.md"><code><b>Getting Started</b></code></a>.
182
183
  - **Highly performant:** as far as we know, Fastify is one of the fastest web
183
184
  frameworks in town, depending on the code complexity we can serve up to 76+
184
185
  thousand requests per second.
185
- - **Extensible:** Fastify is fully extensible via its hooks, plugins and
186
+ - **Extensible:** Fastify is fully extensible via its hooks, plugins, and
186
187
  decorators.
187
- - **Schema based:** even if it is not mandatory we recommend to use [JSON
188
+ - **Schema-based:** even if it is not mandatory we recommend using [JSON
188
189
  Schema](https://json-schema.org/) to validate your routes and serialize your
189
- outputs, internally Fastify compiles the schema in a highly performant
190
+ outputs. Internally Fastify compiles the schema in a highly performant
190
191
  function.
191
192
  - **Logging:** logs are extremely important but are costly; we chose the best
192
193
  logger to almost remove this cost, [Pino](https://github.com/pinojs/pino)!
193
194
  - **Developer friendly:** the framework is built to be very expressive and help
194
- the developer in their daily use, without sacrificing performance and
195
+ developers in their daily use without sacrificing performance and
195
196
  security.
196
197
 
197
198
  ### Benchmarks
@@ -211,10 +212,10 @@ second average
211
212
  | - | | | |
212
213
  | `http.Server` | 16.14.2 | &#10007; | 74,513 |
213
214
 
214
- Benchmarks taken using https://github.com/fastify/benchmarks. This is a
215
- synthetic, "hello world" benchmark that aims to evaluate the framework overhead.
215
+ These benchmarks taken using https://github.com/fastify/benchmarks. This is a
216
+ synthetic "hello world" benchmark that aims to evaluate the framework overhead.
216
217
  The overhead that each framework has on your application depends on your
217
- application, you should __always__ benchmark if performance matters to you.
218
+ application. You should __always__ benchmark if performance matters to you.
218
219
 
219
220
  ## Documentation
220
221
  * [__`Getting Started`__](./docs/Guides/Getting-Started.md)
@@ -244,13 +245,11 @@ application, you should __always__ benchmark if performance matters to you.
244
245
  * [__`Serverless`__](./docs/Guides/Serverless.md)
245
246
  * [__`Recommendations`__](./docs/Guides/Recommendations.md)
246
247
 
247
- 中文文档[地址](https://github.com/fastify/docs-chinese/blob/HEAD/README.md)
248
-
249
248
  ## Ecosystem
250
249
 
251
250
  - [Core](./docs/Guides/Ecosystem.md#core) - Core plugins maintained by the
252
251
  _Fastify_ [team](#team).
253
- - [Community](./docs/Guides/Ecosystem.md#community) - Community supported
252
+ - [Community](./docs/Guides/Ecosystem.md#community) - Community-supported
254
253
  plugins.
255
254
  - [Live Examples](https://github.com/fastify/example) - Multirepo with a broad
256
255
  set of real working examples.
@@ -270,7 +269,7 @@ Fastify's supported version matrix is available in the
270
269
 
271
270
  ## Contributing
272
271
 
273
- Whether reporting bugs, discussing improvements and new ideas or writing code,
272
+ Whether reporting bugs, discussing improvements and new ideas, or writing code,
274
273
  we welcome contributions from anyone and everyone. Please read the [CONTRIBUTING](./CONTRIBUTING.md)
275
274
  guidelines before submitting pull requests.
276
275
 
@@ -284,34 +283,31 @@ listed in alphabetical order.
284
283
  <https://twitter.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
285
284
  * [__Tomas Della Vedova__](https://github.com/delvedor),
286
285
  <https://twitter.com/delvedor>, <https://www.npmjs.com/~delvedor>
286
+ * [__KaKa Ng__](https://github.com/climba03003),
287
+ <https://www.npmjs.com/~climba03003>
287
288
  * [__Manuel Spigolon__](https://github.com/eomm),
288
289
  <https://twitter.com/manueomm>, <https://www.npmjs.com/~eomm>
289
290
  * [__James Sumners__](https://github.com/jsumners),
290
291
  <https://twitter.com/jsumners79>, <https://www.npmjs.com/~jsumners>
291
292
 
292
293
  ### Fastify Core team
293
- * [__Tommaso Allevi__](https://github.com/allevo),
294
- <https://twitter.com/allevitommaso>, <https://www.npmjs.com/~allevo>
294
+ * [__Aras Abbasi__](https://github.com/uzlopak),
295
+ <https://www.npmjs.com/~uzlopak>
295
296
  * [__Harry Brundage__](https://github.com/airhorns/),
296
297
  <https://twitter.com/harrybrundage>, <https://www.npmjs.com/~airhorns>
297
- * [__David Mark Clements__](https://github.com/davidmarkclements),
298
- <https://twitter.com/davidmarkclem>,
299
- <https://www.npmjs.com/~davidmarkclements>
300
298
  * [__Matteo Collina__](https://github.com/mcollina),
301
299
  <https://twitter.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
300
+ * [__Gürgün Dayıoğlu__](https://github.com/gurgunday),
301
+ <https://www.npmjs.com/~gurgunday>
302
302
  * [__Tomas Della Vedova__](https://github.com/delvedor),
303
303
  <https://twitter.com/delvedor>, <https://www.npmjs.com/~delvedor>
304
- * [__Dustin Deus__](https://github.com/StarpTech),
305
- <https://twitter.com/dustindeus>, <https://www.npmjs.com/~starptech>
306
- * [__Ayoub El Khattabi__](https://github.com/AyoubElk),
307
- <https://twitter.com/ayoubelkh>, <https://www.npmjs.com/~ayoubelk>
308
- * [__Denis Fäcke__](https://github.com/SerayaEryn),
309
- <https://twitter.com/serayaeryn>, <https://www.npmjs.com/~serayaeryn>
310
304
  * [__Carlos Fuentes__](https://github.com/metcoder95),
311
305
  <https://twitter.com/metcoder95>, <https://www.npmjs.com/~metcoder95>
312
306
  * [__Vincent Le Goff__](https://github.com/zekth)
313
307
  * [__Luciano Mammino__](https://github.com/lmammino),
314
308
  <https://twitter.com/loige>, <https://www.npmjs.com/~lmammino>
309
+ * [__KaKa Ng__](https://github.com/climba03003),
310
+ <https://www.npmjs.com/~climba03003>
315
311
  * [__Luis Orbaiceta__](https://github.com/luisorbaiceta),
316
312
  <https://twitter.com/luisorbai>, <https://www.npmjs.com/~luisorbaiceta>
317
313
  * [__Maksim Sinik__](https://github.com/fox1t),
@@ -320,63 +316,65 @@ listed in alphabetical order.
320
316
  <https://twitter.com/manueomm>, <https://www.npmjs.com/~eomm>
321
317
  * [__James Sumners__](https://github.com/jsumners),
322
318
  <https://twitter.com/jsumners79>, <https://www.npmjs.com/~jsumners>
323
- * [__Aras Abbasi__](https://github.com/uzlopak),
324
- <https://www.npmjs.com/~uzlopak>
325
- * [__Gürgün Dayıoğlu__](https://github.com/gurgunday),
326
- <https://www.npmjs.com/~gurgunday>
327
319
 
328
320
  ### Fastify Plugins team
329
- * [__Matteo Collina__](https://github.com/mcollina),
330
- <https://twitter.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
331
321
  * [__Harry Brundage__](https://github.com/airhorns/),
332
322
  <https://twitter.com/harrybrundage>, <https://www.npmjs.com/~airhorns>
323
+ * [__Simone Busoli__](https://github.com/simoneb),
324
+ <https://twitter.com/simonebu>, <https://www.npmjs.com/~simoneb>
325
+ * [__Dan Castillo__](https://github.com/dancastillo),
326
+ <https://www.npmjs.com/~dancastillo>
327
+ * [__Matteo Collina__](https://github.com/mcollina),
328
+ <https://twitter.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
329
+ * [__Gürgün Dayıoğlu__](https://github.com/gurgunday),
330
+ <https://www.npmjs.com/~gurgunday>
333
331
  * [__Tomas Della Vedova__](https://github.com/delvedor),
334
332
  <https://twitter.com/delvedor>, <https://www.npmjs.com/~delvedor>
335
- * [__Ayoub El Khattabi__](https://github.com/AyoubElk),
336
- <https://twitter.com/ayoubelkh>, <https://www.npmjs.com/~ayoubelk>
337
333
  * [__Carlos Fuentes__](https://github.com/metcoder95),
338
334
  <https://twitter.com/metcoder95>, <https://www.npmjs.com/~metcoder95>
339
335
  * [__Vincent Le Goff__](https://github.com/zekth)
340
- * [__Salman Mitha__](https://github.com/salmanm),
341
- <https://www.npmjs.com/~salmanm>
336
+ * [__Jean Michelet__](https://github.com/jean-michelet),
337
+ <https://www.npmjs.com/~jean-michelet>
338
+ * [__KaKa Ng__](https://github.com/climba03003),
339
+ <https://www.npmjs.com/~climba03003>
342
340
  * [__Maksim Sinik__](https://github.com/fox1t),
343
341
  <https://twitter.com/maksimsinik>, <https://www.npmjs.com/~fox1t>
344
342
  * [__Frazer Smith__](https://github.com/Fdawgs), <https://www.npmjs.com/~fdawgs>
345
343
  * [__Manuel Spigolon__](https://github.com/eomm),
346
344
  <https://twitter.com/manueomm>, <https://www.npmjs.com/~eomm>
347
- * [__Simone Busoli__](https://github.com/simoneb),
348
- <https://twitter.com/simonebu>, <https://www.npmjs.com/~simoneb>
349
- * [__Gürgün Dayıoğlu__](https://github.com/gurgunday),
350
- <https://www.npmjs.com/~gurgunday>
351
- * [__Dan Castillo__](https://github.com/dancastillo),
352
- <https://www.npmjs.com/~dancastillo>
353
- * [__Jean Michelet__](https://github.com/jean-michelet),
354
- <https://www.npmjs.com/~jean-michelet>
355
-
356
- ### Great Contributors
357
- Great contributors on a specific area in the Fastify ecosystem will be invited
358
- to join this group by Lead Maintainers.
359
345
 
360
- * [__dalisoft__](https://github.com/dalisoft), <https://twitter.com/dalisoft>,
361
- <https://www.npmjs.com/~dalisoft>
362
- * [__Luciano Mammino__](https://github.com/lmammino),
363
- <https://twitter.com/loige>, <https://www.npmjs.com/~lmammino>
364
- * [__Evan Shortiss__](https://github.com/evanshortiss),
365
- <https://twitter.com/evanshortiss>, <https://www.npmjs.com/~evanshortiss>
346
+ ### Emeritus Contributors
347
+ Great contributors to a specific area of the Fastify ecosystem will be invited
348
+ to join this group by Lead Maintainers when they decide to step down from the
349
+ active contributor's group.
366
350
 
367
- **Past Collaborators**
351
+ * [__Tommaso Allevi__](https://github.com/allevo),
352
+ <https://twitter.com/allevitommaso>, <https://www.npmjs.com/~allevo>
353
+ * [__Ethan Arrowood__](https://github.com/Ethan-Arrowood/),
354
+ <https://twitter.com/arrowoodtech>, <https://www.npmjs.com/~ethan_arrowood>
368
355
  * [__Çağatay Çalı__](https://github.com/cagataycali),
369
356
  <https://twitter.com/cagataycali>, <https://www.npmjs.com/~cagataycali>
357
+ * [__David Mark Clements__](https://github.com/davidmarkclements),
358
+ <https://twitter.com/davidmarkclem>,
359
+ <https://www.npmjs.com/~davidmarkclements>
360
+ * [__dalisoft__](https://github.com/dalisoft), <https://twitter.com/dalisoft>,
361
+ <https://www.npmjs.com/~dalisoft>
362
+ * [__Dustin Deus__](https://github.com/StarpTech),
363
+ <https://twitter.com/dustindeus>, <https://www.npmjs.com/~starptech>
364
+ * [__Denis Fäcke__](https://github.com/SerayaEryn),
365
+ <https://twitter.com/serayaeryn>, <https://www.npmjs.com/~serayaeryn>
366
+ * [__Rafael Gonzaga__](https://github.com/rafaelgss),
367
+ <https://twitter.com/_rafaelgss>, <https://www.npmjs.com/~rafaelgss>
370
368
  * [__Trivikram Kamat__](https://github.com/trivikr),
371
369
  <https://twitter.com/trivikram>, <https://www.npmjs.com/~trivikr>
370
+ * [__Ayoub El Khattabi__](https://github.com/AyoubElk),
371
+ <https://twitter.com/ayoubelkh>, <https://www.npmjs.com/~ayoubelk>
372
372
  * [__Cemre Mengu__](https://github.com/cemremengu),
373
373
  <https://twitter.com/cemremengu>, <https://www.npmjs.com/~cemremengu>
374
+ * [__Salman Mitha__](https://github.com/salmanm),
375
+ <https://www.npmjs.com/~salmanm>
374
376
  * [__Nathan Woltman__](https://github.com/nwoltman),
375
377
  <https://twitter.com/NathanWoltman>, <https://www.npmjs.com/~nwoltman>
376
- * [__Ethan Arrowood__](https://github.com/Ethan-Arrowood/),
377
- <https://twitter.com/arrowoodtech>, <https://www.npmjs.com/~ethan_arrowood>
378
- * [__Rafael Gonzaga__](https://github.com/rafaelgss),
379
- <https://twitter.com/_rafaelgss>, <https://www.npmjs.com/~rafaelgss>
380
378
 
381
379
  ## Hosted by
382
380
 
@@ -384,7 +382,7 @@ to join this group by Lead Maintainers.
384
382
  src="https://github.com/openjs-foundation/artwork/blob/main/openjs_foundation/openjs_foundation-logo-horizontal-color.png?raw=true"
385
383
  width="250px;"/>](https://openjsf.org/projects)
386
384
 
387
- We are a [At-Large
385
+ We are an [At-Large
388
386
  Project](https://github.com/openjs-foundation/cross-project-council/blob/HEAD/PROJECT_PROGRESSION.md#at-large-projects)
389
387
  in the [OpenJS Foundation](https://openjsf.org/).
390
388
 
@@ -394,7 +392,7 @@ Support this project by becoming a [SPONSOR](./SPONSORS.md)!
394
392
  Fastify has an [Open Collective](https://opencollective.com/fastify)
395
393
  page where we accept and manage financial contributions.
396
394
 
397
- ## Acknowledgements
395
+ ## Acknowledgments
398
396
 
399
397
  This project is kindly sponsored by:
400
398
  - [NearForm](https://nearform.com)
@@ -403,8 +401,8 @@ This project is kindly sponsored by:
403
401
  Past Sponsors:
404
402
  - [LetzDoIt](https://www.letzdoitapp.com/)
405
403
 
406
- This list includes all companies that support one or more of the team members
407
- in the maintenance of this project.
404
+ This list includes all companies that support one or more team members
405
+ in maintaining this project.
408
406
 
409
407
  ## License
410
408
 
package/SPONSORS.md CHANGED
@@ -16,6 +16,8 @@ _Be the first!_
16
16
  - [Mercedes-Benz Group](https://github.com/mercedes-benz)
17
17
  - [Val Town, Inc.](https://opencollective.com/valtown)
18
18
  - [Handsontable - JavaScript Data Grid](https://handsontable.com/docs/react-data-grid/?utm_source=Fastify_GH&utm_medium=sponsorship&utm_campaign=library_sponsorship_2024)
19
+ - [Jspreadsheet](https://jspreadsheet.com/)
20
+ - [Lokalise - A Localization and Translation Software Tool](https://lokalise.com/?utm_source=Fastify_GH&utm_medium=sponsorship)
19
21
 
20
22
  ## Tier 2
21
23
 
@@ -8,7 +8,7 @@ const path = require('node:path')
8
8
  const factory = AjvStandaloneCompiler({
9
9
  readMode: false,
10
10
  storeFunction (routeOpts, schemaValidationCode) {
11
- const moduleCode = `// This file is autogenerated by ${__filename.replace(__dirname, 'build')}, do not edit
11
+ const moduleCode = `// This file is autogenerated by build/build-validation.js, do not edit
12
12
  /* c8 ignore start */
13
13
  ${schemaValidationCode}
14
14
 
@@ -1,17 +1,17 @@
1
1
  <h1 align="center">Fastify</h1>
2
2
 
3
3
  ## Benchmarking
4
- Benchmarking is important if you want to measure how a change can affect the
5
- performance of your application. We provide a simple way to benchmark your
4
+ Benchmarking is important if you want to measure how a change can affect your
5
+ application's performance. We provide a simple way to benchmark your
6
6
  application from the point of view of a user and contributor. The setup allows
7
7
  you to automate benchmarks in different branches and on different Node.js
8
8
  versions.
9
9
 
10
10
  The modules we will use:
11
- - [Autocannon](https://github.com/mcollina/autocannon): A HTTP/1.1 benchmarking
11
+ - [Autocannon](https://github.com/mcollina/autocannon): An HTTP/1.1 benchmarking
12
12
  tool written in node.
13
13
  - [Branch-comparer](https://github.com/StarpTech/branch-comparer): Checkout
14
- multiple git branches, execute scripts and log the results.
14
+ multiple git branches, execute scripts, and log the results.
15
15
  - [Concurrently](https://github.com/kimmobrunfeldt/concurrently): Run commands
16
16
  concurrently.
17
17
  - [Npx](https://github.com/npm/npx): NPM package runner used to run scripts
@@ -245,7 +245,7 @@ for Postgres, MySQL, SQL Server and SQLite. For MongoDB migrations, please check
245
245
  #### [Postgrator](https://www.npmjs.com/package/postgrator)
246
246
 
247
247
  Postgrator is Node.js SQL migration tool that uses a directory of SQL scripts to
248
- alter the database schema. Each file in a migrations folder need to follow the
248
+ alter the database schema. Each file in a migrations folder needs to follow the
249
249
  pattern: ` [version].[action].[optional-description].sql`.
250
250
 
251
251
  **version:** must be an incrementing number (e.g. `001` or a timestamp).
@@ -77,8 +77,8 @@ server.get('/ping', function (request, reply) {
77
77
  })
78
78
 
79
79
  server.post('/webhook', function (request, reply) {
80
- // It's good practice to validate webhook requests really come from
81
- // whoever you expect. This is skipped in this sample for the sake
80
+ // It's good practice to validate webhook requests come from
81
+ // who you expect. This is skipped in this sample for the sake
82
82
  // of simplicity
83
83
 
84
84
  const { magicKey } = request.body
@@ -448,10 +448,10 @@ have the possibility of giving the customer meaningful information, like how
448
448
  long they should wait before retrying the request. Going even further, by
449
449
  issuing a [`503` status
450
450
  code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503) we're
451
- signaling to our infrastructure components (namely load balancers) we're still
452
- not ready to take incoming requests and they should redirect traffic to other
453
- instances, if available, besides in how long we estimate that will be solved.
454
- All of that in a few simple lines!
451
+ signaling to our infrastructure components (namely load balancers) that we're
452
+ still not ready to take incoming requests and they should redirect traffic to
453
+ other instances, if available. Additionally, we are providing a `Retry-After`
454
+ header with the time in milliseconds the client should wait before retrying.
455
455
 
456
456
  It's noteworthy that we didn't use the `fastify-plugin` wrapper in the `delay`
457
457
  factory. That's because we wanted the `onRequest` hook to only be set within
@@ -524,14 +524,14 @@ Retry-After: 5000
524
524
  }
525
525
  ```
526
526
 
527
- Then we attempt a new request (`req-2`), which was a `GET /ping`. As expected,
527
+ Then we attempted a new request (`req-2`), which was a `GET /ping`. As expected,
528
528
  since that was not one of the requests we asked our plugin to filter, it
529
- succeeded. That could also be used as means of informing an interested party
529
+ succeeded. That could also be used as a means of informing an interested party
530
530
  whether or not we were ready to serve requests (although `/ping` is more
531
531
  commonly associated with *liveness* checks and that would be the responsibility
532
532
  of a *readiness* check -- the curious reader can get more info on these terms
533
533
  [here](https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-setting-up-health-checks-with-readiness-and-liveness-probes))
534
- with the `ready` field. Below is the response for that request:
534
+ with the `ready` field. Below is the response to that request:
535
535
 
536
536
  ```sh
537
537
  HTTP/1.1 200 OK
@@ -547,7 +547,7 @@ Keep-Alive: timeout=5
547
547
  }
548
548
  ```
549
549
 
550
- After that there were more interesting log messages:
550
+ After that, there were more interesting log messages:
551
551
 
552
552
  <!-- markdownlint-disable -->
553
553
  ```sh
@@ -86,6 +86,8 @@ section.
86
86
  [`simple-oauth2`](https://github.com/lelylan/simple-oauth2).
87
87
  - [`@fastify/one-line-logger`](https://github.com/fastify/one-line-logger) Formats
88
88
  Fastify's logs into a nice one-line message.
89
+ - [`@fastify/otel`](https://github.com/fastify/otel) OpenTelemetry
90
+ instrumentation library.
89
91
  - [`@fastify/passport`](https://github.com/fastify/fastify-passport) Use Passport
90
92
  strategies to authenticate requests and protect route.
91
93
  - [`@fastify/postgres`](https://github.com/fastify/fastify-postgres) Fastify
@@ -198,6 +200,8 @@ section.
198
200
  to go!
199
201
  A plugin to implement [Lyra](https://github.com/nearform/lyra) search engine
200
202
  on Fastify
203
+ - [`@jerome1337/fastify-enforce-routes-pattern`](https://github.com/Jerome1337/fastify-enforce-routes-pattern)
204
+ A Fastify plugin that enforces naming pattern for routes path.
201
205
  - [`@joggr/fastify-prisma`](https://github.com/joggrdocs/fastify-prisma)
202
206
  A plugin for accessing an instantiated PrismaClient on your server.
203
207
  - [`@mgcrea/fastify-graceful-exit`](https://github.com/mgcrea/fastify-graceful-exit)
@@ -214,7 +218,7 @@ section.
214
218
  A custom compact pino-base prettifier
215
219
  - [`@pybot/fastify-autoload`](https://github.com/kunal097/fastify-autoload)
216
220
  Plugin to generate routes automatically with valid json content
217
- - [`@scalar/fastify-api-reference`](https://github.com/scalar/scalar/tree/main/packages/fastify-api-reference)
221
+ - [`@scalar/fastify-api-reference`](https://github.com/scalar/scalar/tree/main/integrations/fastify)
218
222
  Beautiful OpenAPI/Swagger API references for Fastify
219
223
  - [`@trubavuong/fastify-seaweedfs`](https://github.com/trubavuong/fastify-seaweedfs)
220
224
  SeaweedFS for Fastify
@@ -55,7 +55,7 @@ fastify.post('/the/url', { schema }, handler)
55
55
 
56
56
  ### Reuse
57
57
 
58
- With `fluent-json-schema` you can manipulate your schemas more easily and
58
+ With `fluent-json-schema`, you can manipulate your schemas more easily and
59
59
  programmatically and then reuse them thanks to the `addSchema()` method. You can
60
60
  refer to the schema in two different manners that are detailed in the
61
61
  [Validation and
@@ -106,7 +106,7 @@ of your code.
106
106
  Fastify offers an easy platform that helps to solve all of the problems outlined
107
107
  above, and more!
108
108
 
109
- > ## Note
109
+ > **Note**
110
110
  > The above examples, and subsequent examples in this document, default to
111
111
  > listening *only* on the localhost `127.0.0.1` interface. To listen on all
112
112
  > available IPv4 interfaces the example should be modified to listen on
@@ -128,6 +128,9 @@ above, and more!
128
128
  >
129
129
  > When deploying to a Docker (or another type of) container using `0.0.0.0` or
130
130
  > `::` would be the easiest method for exposing the application.
131
+ >
132
+ > Note that when using `0.0.0.0`, the address provided in the callback argument
133
+ > above will be the first address the wildcard refers to.
131
134
 
132
135
  ### Your first plugin
133
136
  <a id="first-plugin"></a>
@@ -417,7 +420,7 @@ In this way, you will always have access to all of the properties declared in
417
420
  the current scope.
418
421
 
419
422
  As discussed previously, Fastify offers a solid encapsulation model, to help you
420
- build your application as single and independent services. If you want to
423
+ build your application as independent services. If you want to
421
424
  register a plugin only for a subset of routes, you just have to replicate the
422
425
  above structure.
423
426
  ```
@@ -552,15 +555,16 @@ an amazing [ecosystem](./Ecosystem.md)!
552
555
  <a id="test-server"></a>
553
556
 
554
557
  Fastify does not offer a testing framework, but we do recommend a way to write
555
- your tests that use the features and architecture of Fastify.
558
+ your tests that uses the features and architecture of Fastify.
556
559
 
557
560
  Read the [testing](./Testing.md) documentation to learn more!
558
561
 
559
562
  ### Run your server from CLI
560
563
  <a id="cli"></a>
561
564
 
562
- Fastify also has CLI integration thanks to
563
- [fastify-cli](https://github.com/fastify/fastify-cli).
565
+ Fastify also has CLI integration via
566
+ [fastify-cli](https://github.com/fastify/fastify-cli),
567
+ a separate tool for scaffolding and managing Fastify projects.
564
568
 
565
569
  First, install `fastify-cli`:
566
570
 
@@ -19,7 +19,7 @@ This table of contents is in alphabetical order.
19
19
  practical guide on detecting if and when a client aborts a request.
20
20
  + [Ecosystem](./Ecosystem.md): Lists all core plugins and many known community
21
21
  plugins.
22
- + [Fluent Schema](./Fluent-Schema.md): Shows how writing JSON Schema can be
22
+ + [Fluent Schema](./Fluent-Schema.md): Shows how JSON Schema can be
23
23
  written with a fluent API and used in Fastify.
24
24
  + [Getting Started](./Getting-Started.md): Introduction tutorial for Fastify.
25
25
  This is where beginners should start.
@@ -210,7 +210,7 @@ fastify.get('/posts/:id?', (request, reply) => {
210
210
  The [variadic signature](https://en.wikipedia.org/wiki/Variadic_function) of the
211
211
  `fastify.listen()` method is now deprecated.
212
212
 
213
- Prior to this release, the following invocations of this method were valid:
213
+ Before this release, the following invocations of this method were valid:
214
214
 
215
215
  - `fastify.listen(8000)`
216
216
  - `fastify.listen(8000, ‘127.0.0.1’)`
@@ -472,7 +472,7 @@ or turn it into a function
472
472
 
473
473
  ```js
474
474
  // v5
475
- fastify.decorateRequest('myObject', () => { hello: 'world' });
475
+ fastify.decorateRequest('myObject', () => ({ hello: 'world' }));
476
476
  ```
477
477
 
478
478
  or as a getter
@@ -524,6 +524,17 @@ fastify.register(function (instance, opts, done) {
524
524
  });
525
525
  ```
526
526
 
527
+ ### Requests now have `host`, `hostname`, and `port`, and `hostname` no longer includes the port number
528
+
529
+ In Fastify v4, `req.hostname` would include both the hostname and the
530
+ server’s port, so locally it might have the value `localhost:1234`.
531
+ With v5, we aligned to the Node.js URL object and now include `host`, `hostname`,
532
+ and `port` properties. `req.host` has the same value as `req.hostname` did in v4,
533
+ while `req.hostname` includes the hostname _without_ a port if a port is present,
534
+ and `req.port` contains just the port number.
535
+ See [#4766](https://github.com/fastify/fastify/pull/4766)
536
+ and [#4682](https://github.com/fastify/fastify/issues/4682) for more information.
537
+
527
538
  ### Removes `getDefaultRoute` and `setDefaultRoute` methods
528
539
 
529
540
  The `getDefaultRoute` and `setDefaultRoute` methods have been removed in v5.
@@ -709,4 +720,3 @@ contributing to those that are capable of accepting sponsorships.
709
720
  | voxpelli | [❤️ sponsor](https://github.com/sponsors/voxpelli) | fastify |
710
721
  | weixinwu | | fastify-cli |
711
722
  | zetaraku | | fastify-cli |
712
-
@@ -71,8 +71,8 @@ order of plugins. *How?* Glad you asked, check out
71
71
  [`avvio`](https://github.com/mcollina/avvio)! Fastify starts loading the plugin
72
72
  __after__ `.listen()`, `.inject()` or `.ready()` are called.
73
73
 
74
- Inside a plugin you can do whatever you want, register routes, utilities (we
75
- will see this in a moment) and do nested registers, just remember to call `done`
74
+ Inside a plugin you can do whatever you want, register routes and utilities (we
75
+ will see this in a moment), and do nested registers, just remember to call `done`
76
76
  when everything is set up!
77
77
  ```js
78
78
  module.exports = function (fastify, options, done) {
@@ -117,7 +117,7 @@ Now you can access your utility just by calling `fastify.util` whenever you need
117
117
  it - even inside your test.
118
118
 
119
119
  And here starts the magic; do you remember how just now we were talking about
120
- encapsulation? Well, using `register` and `decorate` in conjunction enable
120
+ encapsulation? Well, using `register` and `decorate` in conjunction enables
121
121
  exactly that, let me show you an example to clarify this:
122
122
  ```js
123
123
  fastify.register((instance, opts, done) => {
@@ -137,7 +137,7 @@ Inside the second register call `instance.util` will throw an error because
137
137
  `util` exists only inside the first register context.
138
138
 
139
139
  Let's step back for a moment and dig deeper into this: every time you use the
140
- `register` API, a new context is created which avoids the negative situations
140
+ `register` API, a new context is created that avoids the negative situations
141
141
  mentioned above.
142
142
 
143
143
  Do note that encapsulation applies to the ancestors and siblings, but not the
@@ -202,7 +202,7 @@ a utility that also needs access to the `request` and `reply` instance,
202
202
  a function that is defined using the `function` keyword is needed instead
203
203
  of an *arrow function expression*.
204
204
 
205
- In the same way you can do this for the `request` object:
205
+ You can do the same for the `request` object:
206
206
  ```js
207
207
  fastify.decorate('getHeader', (req, header) => {
208
208
  return req.headers[header]
@@ -395,7 +395,7 @@ As we mentioned earlier, Fastify starts loading its plugins __after__
395
395
  have been declared. This means that, even though the plugin may inject variables
396
396
  to the external Fastify instance via [`decorate`](../Reference/Decorators.md),
397
397
  the decorated variables will not be accessible before calling `.listen()`,
398
- `.inject()` or `.ready()`.
398
+ `.inject()`, or `.ready()`.
399
399
 
400
400
  In case you rely on a variable injected by a preceding plugin and want to pass
401
401
  that in the `options` argument of `register`, you can do so by using a function