fastify 5.2.1 → 5.3.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.
Files changed (85) hide show
  1. package/LICENSE +1 -1
  2. package/PROJECT_CHARTER.md +7 -7
  3. package/README.md +24 -25
  4. package/SPONSORS.md +1 -0
  5. package/docs/Guides/Benchmarking.md +4 -4
  6. package/docs/Guides/Database.md +1 -1
  7. package/docs/Guides/Delay-Accepting-Requests.md +10 -10
  8. package/docs/Guides/Ecosystem.md +7 -1
  9. package/docs/Guides/Fluent-Schema.md +1 -1
  10. package/docs/Guides/Getting-Started.md +9 -5
  11. package/docs/Guides/Index.md +1 -1
  12. package/docs/Guides/Migration-Guide-V4.md +1 -1
  13. package/docs/Guides/Migration-Guide-V5.md +12 -2
  14. package/docs/Guides/Plugins-Guide.md +6 -6
  15. package/docs/Guides/Serverless.md +14 -48
  16. package/docs/Guides/Style-Guide.md +2 -2
  17. package/docs/Guides/Testing.md +2 -2
  18. package/docs/Guides/Write-Plugin.md +2 -3
  19. package/docs/Reference/ContentTypeParser.md +58 -78
  20. package/docs/Reference/Decorators.md +249 -60
  21. package/docs/Reference/Encapsulation.md +28 -33
  22. package/docs/Reference/Errors.md +52 -53
  23. package/docs/Reference/HTTP2.md +7 -7
  24. package/docs/Reference/Hooks.md +31 -30
  25. package/docs/Reference/LTS.md +10 -15
  26. package/docs/Reference/Lifecycle.md +19 -24
  27. package/docs/Reference/Logging.md +59 -56
  28. package/docs/Reference/Middleware.md +19 -19
  29. package/docs/Reference/Plugins.md +55 -71
  30. package/docs/Reference/Principles.md +25 -30
  31. package/docs/Reference/Reply.md +11 -10
  32. package/docs/Reference/Request.md +89 -98
  33. package/docs/Reference/Routes.md +108 -128
  34. package/docs/Reference/Server.md +18 -16
  35. package/docs/Reference/Type-Providers.md +19 -21
  36. package/docs/Reference/TypeScript.md +1 -18
  37. package/docs/Reference/Validation-and-Serialization.md +134 -159
  38. package/docs/Reference/Warnings.md +22 -25
  39. package/fastify.js +3 -2
  40. package/lib/contentTypeParser.js +7 -8
  41. package/lib/decorate.js +18 -3
  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 +17 -2
  47. package/lib/request.js +28 -2
  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 +12 -12
  53. package/test/bundler/esbuild/package.json +1 -1
  54. package/test/close.test.js +125 -108
  55. package/test/custom-parser-async.test.js +34 -36
  56. package/test/custom-parser.4.test.js +55 -38
  57. package/test/decorator.test.js +174 -4
  58. package/test/fastify-instance.test.js +12 -2
  59. package/test/genReqId.test.js +125 -174
  60. package/test/has-route.test.js +1 -3
  61. package/test/hooks.on-listen.test.js +17 -14
  62. package/test/internals/content-type-parser.test.js +1 -1
  63. package/test/internals/errors.test.js +14 -1
  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 +50 -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/register.test.js +55 -50
  71. package/test/request-error.test.js +114 -94
  72. package/test/route-shorthand.test.js +36 -32
  73. package/test/stream.5.test.js +35 -33
  74. package/test/throw.test.js +87 -91
  75. package/test/toolkit.js +32 -0
  76. package/test/trust-proxy.test.js +23 -23
  77. package/test/types/instance.test-d.ts +4 -0
  78. package/test/types/reply.test-d.ts +1 -0
  79. package/test/types/request.test-d.ts +4 -0
  80. package/test/types/type-provider.test-d.ts +40 -0
  81. package/test/upgrade.test.js +32 -33
  82. package/types/instance.d.ts +6 -0
  83. package/types/reply.d.ts +1 -0
  84. package/types/request.d.ts +2 -0
  85. package/types/type-provider.d.ts +12 -3
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
 
@@ -345,9 +344,9 @@ listed in alphabetical order.
345
344
  <https://twitter.com/manueomm>, <https://www.npmjs.com/~eomm>
346
345
 
347
346
  ### Emeritus Contributors
348
- Great contributors on a specific area in the Fastify ecosystem will be invited
347
+ Great contributors to a specific area of the Fastify ecosystem will be invited
349
348
  to join this group by Lead Maintainers when they decide to step down from the
350
- active contributors group.
349
+ active contributor's group.
351
350
 
352
351
  * [__Tommaso Allevi__](https://github.com/allevo),
353
352
  <https://twitter.com/allevitommaso>, <https://www.npmjs.com/~allevo>
@@ -383,7 +382,7 @@ active contributors group.
383
382
  src="https://github.com/openjs-foundation/artwork/blob/main/openjs_foundation/openjs_foundation-logo-horizontal-color.png?raw=true"
384
383
  width="250px;"/>](https://openjsf.org/projects)
385
384
 
386
- We are a [At-Large
385
+ We are an [At-Large
387
386
  Project](https://github.com/openjs-foundation/cross-project-council/blob/HEAD/PROJECT_PROGRESSION.md#at-large-projects)
388
387
  in the [OpenJS Foundation](https://openjsf.org/).
389
388
 
@@ -393,7 +392,7 @@ Support this project by becoming a [SPONSOR](./SPONSORS.md)!
393
392
  Fastify has an [Open Collective](https://opencollective.com/fastify)
394
393
  page where we accept and manage financial contributions.
395
394
 
396
- ## Acknowledgements
395
+ ## Acknowledgments
397
396
 
398
397
  This project is kindly sponsored by:
399
398
  - [NearForm](https://nearform.com)
@@ -402,8 +401,8 @@ This project is kindly sponsored by:
402
401
  Past Sponsors:
403
402
  - [LetzDoIt](https://www.letzdoitapp.com/)
404
403
 
405
- This list includes all companies that support one or more of the team members
406
- in the maintenance of this project.
404
+ This list includes all companies that support one or more team members
405
+ in maintaining this project.
407
406
 
408
407
  ## License
409
408
 
package/SPONSORS.md CHANGED
@@ -16,6 +16,7 @@ _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
+ - [Lokalise - A Localization and Translation Software Tool](https://lokalise.com/?utm_source=Fastify_GH&utm_medium=sponsorship)
19
20
 
20
21
  ## Tier 2
21
22
 
@@ -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
@@ -456,6 +460,8 @@ middlewares into Fastify plugins
456
460
  Lightweight cache plugin
457
461
  - [`fastify-list-routes`](https://github.com/chuongtrh/fastify-list-routes)
458
462
  A simple plugin for Fastify to list all available routes.
463
+ - [`fastify-lm`](https://github.com/galiprandi/fastify-lm#readme)
464
+ Use OpenAI, Claude, Google, Deepseek, and others LMs with one Fastify plugin.
459
465
  - [`fastify-loader`](https://github.com/TheNoim/fastify-loader) Load routes from
460
466
  a directory and inject the Fastify instance in each file.
461
467
  - [`fastify-log-controller`](https://github.com/Eomm/fastify-log-controller/)
@@ -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
@@ -25,11 +25,11 @@ snippet of code.
25
25
  ### Contents
26
26
 
27
27
  - [AWS](#aws)
28
+ - [Genezio](#genezio)
28
29
  - [Google Cloud Functions](#google-cloud-functions)
29
30
  - [Google Firebase Functions](#google-firebase-functions)
30
31
  - [Google Cloud Run](#google-cloud-run)
31
32
  - [Netlify Lambda](#netlify-lambda)
32
- - [Platformatic Cloud](#platformatic-cloud)
33
33
  - [Vercel](#vercel)
34
34
 
35
35
  ## AWS
@@ -129,6 +129,14 @@ If you need to integrate with more AWS services, take a look at
129
129
  [@h4ad/serverless-adapter](https://viniciusl.com.br/serverless-adapter/docs/main/frameworks/fastify)
130
130
  on Fastify to find out how to integrate.
131
131
 
132
+ ## Genezio
133
+
134
+ [Genezio](https://genezio.com/) is a platform designed to simplify the deployment
135
+ of serverless applications to the cloud.
136
+
137
+ [Genezio has a dedicated guide for deploying a Fastify application.](https://genezio.com/docs/frameworks/fastify/)
138
+
139
+
132
140
  ## Google Cloud Functions
133
141
 
134
142
  ### Creation of Fastify instance
@@ -280,8 +288,8 @@ const { onRequest } = require("firebase-functions/v2/https")
280
288
  ### Creation of Fastify instance
281
289
 
282
290
  Create the Fastify instance and encapsulate the returned application instance
283
- in a function which will register routes, await the server's processing of
284
- plugins, hooks and other settings. As follows:
291
+ in a function that will register routes, await the server's processing of
292
+ plugins, hooks, and other settings. As follows:
285
293
 
286
294
  ```js
287
295
  const fastify = require("fastify")({
@@ -299,7 +307,7 @@ const fastifyApp = async (request, reply) => {
299
307
 
300
308
  Firebase Function's HTTP layer already parses the request
301
309
  and makes a JSON payload available. It also provides access
302
- to the raw body, unparsed, which is useful in order to calculate
310
+ to the raw body, unparsed, which is useful for calculating
303
311
  request signatures to validate HTTP webhooks.
304
312
 
305
313
  Add as follows to the `registerRoutes()` function:
@@ -384,7 +392,7 @@ familiar with gcloud or just follow their
384
392
 
385
393
  ### Adjust Fastify server
386
394
 
387
- In order for Fastify to properly listen for requests within the container, be
395
+ For Fastify to properly listen for requests within the container, be
388
396
  sure to set the correct port and address:
389
397
 
390
398
  ```js
@@ -562,49 +570,7 @@ Add this command to your `package.json` *scripts*
562
570
  }
563
571
  ```
564
572
 
565
- Then it should work fine
566
-
567
- ## Platformatic Cloud
568
-
569
- [Platformatic](https://platformatic.dev) provides zero-configuration deployment
570
- for Node.js applications.
571
- To use it now, you should wrap your existing Fastify application inside a
572
- [Platformatic Service](https://oss.platformatic.dev/docs/reference/service/introduction),
573
- by running the following:
574
-
575
-
576
- ```bash
577
- npm create platformatic@latest -- service
578
- ```
579
-
580
- The wizard would ask you to fill in a few answers:
581
-
582
- ```
583
- ? Where would you like to create your project? .
584
- ? Do you want to run npm install? yes
585
- ? Do you want to use TypeScript? no
586
- ? What port do you want to use? 3042
587
- [13:04:14] INFO: Configuration file platformatic.service.json successfully created.
588
- [13:04:14] INFO: Environment file .env successfully created.
589
- [13:04:14] INFO: Plugins folder "plugins" successfully created.
590
- [13:04:14] INFO: Routes folder "routes" successfully created.
591
- ? Do you want to create the github action to deploy this application to Platformatic Cloud dynamic workspace? no
592
- ? Do you want to create the github action to deploy this application to Platformatic Cloud static workspace? no
593
- ```
594
-
595
- Then, head to [Platformatic Cloud](https://platformatic.cloud) and sign in
596
- with your GitHub account.
597
- Create your first application and a static workspace: be careful to download the
598
- API key as an env file, e.g. `yourworkspace.txt`.
599
-
600
- Then, you can easily deploy your application with the following command:
601
-
602
- ```bash
603
- platformatic deploy --keys `yourworkspace.txt`
604
- ```
605
-
606
- Check out the [Full Guide](https://blog.platformatic.dev/how-to-migrate-a-fastify-app-to-platformatic-service)
607
- on how to wrap Fastify application in Platformatic.
573
+ Then it should work fine.
608
574
 
609
575
  ## Vercel
610
576
 
@@ -83,7 +83,7 @@ Result:
83
83
 
84
84
  Make sure you avoid copying other people's work. Keep it as original as
85
85
  possible. You can learn from what they have done and reference where it is from
86
- if you used a particular quote from their work.
86
+ if you use a particular quote from their work.
87
87
 
88
88
 
89
89
  ## Word Choice
@@ -217,7 +217,7 @@ Styles](https://medium.com/better-programming/string-case-styles-camel-pascal-sn
217
217
 
218
218
  ### Hyperlinks
219
219
 
220
- Hyperlinks should have a clear title of what it references. Here is how your
220
+ Hyperlinks should have a clear title of what they reference. Here is how your
221
221
  hyperlink should look:
222
222
 
223
223
  ```MD
@@ -340,10 +340,10 @@ test('should ...', {only: true}, t => ...)
340
340
  ```
341
341
  2. Run `node --test`
342
342
  ```bash
343
- > node --test --test-only --node-arg=--inspect-brk test/<test-file.test.js>
343
+ > node --test --test-only --inspect-brk test/<test-file.test.js>
344
344
  ```
345
345
  - `--test-only` specifies to run tests with the `only` option enabled
346
- - `--node-arg=--inspect-brk` will launch the node debugger
346
+ - `--inspect-brk` will launch the node debugger
347
347
  3. In VS Code, create and launch a `Node.js: Attach` debug configuration. No
348
348
  modification should be necessary.
349
349