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
@@ -102,8 +102,8 @@
102
102
  <a id="error-handling"></a>
103
103
 
104
104
  #### Uncaught Errors
105
- In Node.js, uncaught errors are likely to cause memory leaks, file descriptor
106
- leaks, and other major production issues.
105
+ In Node.js, uncaught errors can cause memory leaks, file descriptor leaks, and
106
+ other major production issues.
107
107
  [Domains](https://nodejs.org/en/docs/guides/domain-postmortem/) were a failed
108
108
  attempt to fix this.
109
109
 
@@ -112,29 +112,28 @@ way to deal with them is to
112
112
  [crash](https://nodejs.org/api/process.html#process_warning_using_uncaughtexception_correctly).
113
113
 
114
114
  #### Catching Errors In Promises
115
- If you are using promises, you should attach a `.catch()` handler synchronously.
115
+ When using promises, attach a `.catch()` handler synchronously.
116
116
 
117
117
  ### Errors In Fastify
118
- Fastify follows an all-or-nothing approach and aims to be lean and optimal as
119
- much as possible. The developer is responsible for making sure that the errors
120
- are handled properly.
118
+ Fastify follows an all-or-nothing approach and aims to be lean and optimal. The
119
+ developer is responsible for ensuring errors are handled properly.
121
120
 
122
121
  #### Errors In Input Data
123
- Most errors are a result of unexpected input data, so we recommend [validating
124
- your input data against a JSON schema](./Validation-and-Serialization.md).
122
+ Most errors result from unexpected input data, so it is recommended to
123
+ [validate input data against a JSON schema](./Validation-and-Serialization.md).
125
124
 
126
125
  #### Catching Uncaught Errors In Fastify
127
- Fastify tries to catch as many uncaught errors as it can without hindering
126
+ Fastify tries to catch as many uncaught errors as possible without hindering
128
127
  performance. This includes:
129
128
 
130
129
  1. synchronous routes, e.g. `app.get('/', () => { throw new Error('kaboom') })`
131
130
  2. `async` routes, e.g. `app.get('/', async () => { throw new Error('kaboom')
132
131
  })`
133
132
 
134
- The error in both cases will be caught safely and routed to Fastify's default
135
- error handler for a generic `500 Internal Server Error` response.
133
+ In both cases, the error will be caught safely and routed to Fastify's default
134
+ error handler, resulting in a generic `500 Internal Server Error` response.
136
135
 
137
- To customize this behavior you should use
136
+ To customize this behavior, use
138
137
  [`setErrorHandler`](./Server.md#seterrorhandler).
139
138
 
140
139
  ### Errors In Fastify Lifecycle Hooks And A Custom Error Handler
@@ -144,52 +143,50 @@ From the [Hooks documentation](./Hooks.md#manage-errors-from-a-hook):
144
143
  > `done()` and Fastify will automatically close the request and send the
145
144
  > appropriate error code to the user.
146
145
 
147
- When a custom error handler has been defined through
148
- [`setErrorHandler`](./Server.md#seterrorhandler), the custom error handler will
149
- receive the error passed to the `done()` callback (or through other supported
150
- automatic error handling mechanisms). If `setErrorHandler` has been used
151
- multiple times to define multiple handlers, the error will be routed to the most
152
- precedent handler defined within the error [encapsulation
153
- context](./Encapsulation.md). Error handlers are fully encapsulated, so a
154
- `setErrorHandler` call within a plugin will limit the error handler to that
155
- plugin's context.
146
+ When a custom error handler is defined through
147
+ [`setErrorHandler`](./Server.md#seterrorhandler), it will receive the error
148
+ passed to the `done()` callback or through other supported automatic error
149
+ handling mechanisms. If `setErrorHandler` is used multiple times, the error will
150
+ be routed to the most precedent handler within the error
151
+ [encapsulation context](./Encapsulation.md). Error handlers are fully
152
+ encapsulated, so a `setErrorHandler` call within a plugin will limit the error
153
+ handler to that plugin's context.
156
154
 
157
155
  The root error handler is Fastify's generic error handler. This error handler
158
156
  will use the headers and status code in the `Error` object, if they exist. The
159
157
  headers and status code will not be automatically set if a custom error handler
160
158
  is provided.
161
159
 
162
- Some things to consider in your custom error handler:
160
+ The following should be considered when using a custom error handler:
163
161
 
164
- - you can `reply.send(data)`, which will behave as it would in [regular route
165
- handlers](./Reply.md#senddata)
162
+ - `reply.send(data)` behaves as in [regular route handlers](./Reply.md#senddata)
166
163
  - objects are serialized, triggering the `preSerialization` lifecycle hook if
167
- you have one defined
168
- - strings, buffers, and streams are sent to the client, with appropriate
169
- headers (no serialization)
170
-
171
- - You can throw a new error in your custom error handler - errors (new error or
172
- the received error parameter re-thrown) - will call the parent `errorHandler`.
173
- - `onError` hook will be triggered once only for the first error being thrown.
174
- - an error will not be triggered twice from a lifecycle hook - Fastify
175
- internally monitors the error invocation to avoid infinite loops for errors
176
- thrown in the reply phases of the lifecycle. (those after the route handler)
177
-
178
- When utilizing Fastify's custom error handling through [`setErrorHandler`](./Server.md#seterrorhandler),
179
- you should be aware of how errors are propagated between custom and default
180
- error handlers.
181
-
182
- If a plugin's error handler re-throws an error, and the error is not an
183
- instance of [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
184
- (as seen in the `/bad` route in the following example), it will not propagate
185
- to the parent context error handler. Instead, it will be caught by the default
186
- error handler.
187
-
188
- To ensure consistent error handling, it is recommended to throw instances of
189
- `Error`. For instance, in the following example, replacing `throw 'foo'` with
190
- `throw new Error('foo')` in the `/bad` route ensures that errors propagate through
191
- the custom error handling chain as intended. This practice helps avoid potential
192
- pitfalls when working with custom error handling in Fastify.
164
+ defined
165
+ - strings, buffers, and streams are sent to the client with appropriate headers
166
+ (no serialization)
167
+
168
+ - Throwing a new error in a custom error handler will call the parent
169
+ `errorHandler`.
170
+ - The `onError` hook will be triggered once for the first error thrown
171
+ - An error will not be triggered twice from a lifecycle hook. Fastify
172
+ internally monitors error invocation to avoid infinite loops for errors
173
+ thrown in the reply phases of the lifecycle (those after the route handler)
174
+
175
+ When using Fastify's custom error handling through
176
+ [`setErrorHandler`](./Server.md#seterrorhandler), be aware of how errors are
177
+ propagated between custom and default error handlers.
178
+
179
+ If a plugin's error handler re-throws an error that is not an instance of
180
+ [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error),
181
+ it will not propagate to the parent context error handler. Instead, it will be
182
+ caught by the default error handler. This can be seen in the `/bad` route of the
183
+ example below.
184
+
185
+ To ensure consistent error handling, throw instances of `Error`. For example,
186
+ replace `throw 'foo'` with `throw new Error('foo')` in the `/bad` route to
187
+ ensure errors propagate through the custom error handling chain as intended.
188
+ This practice helps avoid potential pitfalls when working with custom error
189
+ handling in Fastify.
193
190
 
194
191
  For example:
195
192
  ```js
@@ -242,7 +239,7 @@ You can access `errorCodes` for mapping:
242
239
  // ESM
243
240
  import { errorCodes } from 'fastify'
244
241
 
245
- // CommonJs
242
+ // CommonJS
246
243
  const errorCodes = require('fastify').errorCodes
247
244
  ```
248
245
 
@@ -267,7 +264,7 @@ fastify.setErrorHandler(function (error, request, reply) {
267
264
  // Send error response
268
265
  reply.status(500).send({ ok: false })
269
266
  } else {
270
- // fastify will use parent error handler to handle this
267
+ // Fastify will use parent error handler to handle this
271
268
  reply.send(error)
272
269
  }
273
270
  })
@@ -282,7 +279,7 @@ fastify.listen({ port: 3000 }, function (err, address) {
282
279
  })
283
280
  ```
284
281
 
285
- Below is a table with all the error codes that Fastify uses.
282
+ Below is a table with all the error codes used by Fastify.
286
283
 
287
284
  | Code | Description | How to solve | Discussion |
288
285
  |------|-------------|--------------|------------|
@@ -2,11 +2,11 @@
2
2
 
3
3
  ## HTTP2
4
4
 
5
- _Fastify_ supports HTTP2 over either HTTPS (h2) or plaintext (h2c).
5
+ _Fastify_ supports HTTP2 over HTTPS (h2) or plaintext (h2c).
6
6
 
7
7
  Currently, none of the HTTP2-specific APIs are available through _Fastify_, but
8
- Node's `req` and `res` can be accessed through our `Request` and `Reply`
9
- interface. PRs are welcome.
8
+ Node's `req` and `res` can be accessed through the `Request` and `Reply`
9
+ interfaces. PRs are welcome.
10
10
 
11
11
  ### Secure (HTTPS)
12
12
 
@@ -61,7 +61,7 @@ fastify.get('/', function (request, reply) {
61
61
  fastify.listen({ port: 3000 })
62
62
  ```
63
63
 
64
- You can test your new server with:
64
+ Test the new server with:
65
65
 
66
66
  ```
67
67
  $ npx h2url https://localhost:3000
@@ -69,8 +69,8 @@ $ npx h2url https://localhost:3000
69
69
 
70
70
  ### Plain or insecure
71
71
 
72
- If you are building microservices, you can connect to HTTP2 in plain text,
73
- however, this is not supported by browsers.
72
+ For microservices, HTTP2 can connect in plain text, but this is not
73
+ supported by browsers.
74
74
 
75
75
  ```js
76
76
  'use strict'
@@ -86,7 +86,7 @@ fastify.get('/', function (request, reply) {
86
86
  fastify.listen({ port: 3000 })
87
87
  ```
88
88
 
89
- You can test your new server with:
89
+ Test the new server with:
90
90
 
91
91
  ```
92
92
  $ npx h2url http://localhost:3000
@@ -34,9 +34,9 @@ are Request/Reply hooks and application hooks:
34
34
  - [Using Hooks to Inject Custom Properties](#using-hooks-to-inject-custom-properties)
35
35
  - [Diagnostics Channel Hooks](#diagnostics-channel-hooks)
36
36
 
37
- **Notice:** the `done` callback is not available when using `async`/`await` or
38
- returning a `Promise`. If you do invoke a `done` callback in this situation
39
- unexpected behavior may occur, e.g. duplicate invocation of handlers.
37
+ > 🛈 Note: The `done` callback is not available when using `async`/`await` or
38
+ > returning a `Promise`. If you do invoke a `done` callback in this situation
39
+ > unexpected behavior may occur, e.g. duplicate invocation of handlers.
40
40
 
41
41
  ## Request/Reply Hooks
42
42
 
@@ -68,9 +68,9 @@ fastify.addHook('onRequest', async (request, reply) => {
68
68
  })
69
69
  ```
70
70
 
71
- **Notice:** in the [onRequest](#onrequest) hook, `request.body` will always be
72
- `undefined`, because the body parsing happens before the
73
- [preValidation](#prevalidation) hook.
71
+ > 🛈 Note: In the [onRequest](#onrequest) hook, `request.body` will always be
72
+ > `undefined`, because the body parsing happens before the
73
+ > [preValidation](#prevalidation) hook.
74
74
 
75
75
  ### preParsing
76
76
 
@@ -98,17 +98,17 @@ fastify.addHook('preParsing', async (request, reply, payload) => {
98
98
  })
99
99
  ```
100
100
 
101
- **Notice:** in the [preParsing](#preparsing) hook, `request.body` will always be
102
- `undefined`, because the body parsing happens before the
103
- [preValidation](#prevalidation) hook.
101
+ > 🛈 Note: In the [preParsing](#preparsing) hook, `request.body` will always be
102
+ > `undefined`, because the body parsing happens before the
103
+ > [preValidation](#prevalidation) hook.
104
104
 
105
- **Notice:** you should also add a `receivedEncodedLength` property to the
106
- returned stream. This property is used to correctly match the request payload
107
- with the `Content-Length` header value. Ideally, this property should be updated
108
- on each received chunk.
105
+ > 🛈 Note: You should also add a `receivedEncodedLength` property to the
106
+ > returned stream. This property is used to correctly match the request payload
107
+ > with the `Content-Length` header value. Ideally, this property should be updated
108
+ > on each received chunk.
109
109
 
110
- **Notice:** The size of the returned stream is checked to not exceed the limit
111
- set in [`bodyLimit`](./Server.md#bodylimit) option.
110
+ > 🛈 Note: The size of the returned stream is checked to not exceed the limit
111
+ > set in [`bodyLimit`](./Server.md#bodylimit) option.
112
112
 
113
113
  ### preValidation
114
114
 
@@ -166,8 +166,8 @@ fastify.addHook('preSerialization', async (request, reply, payload) => {
166
166
  })
167
167
  ```
168
168
 
169
- Note: the hook is NOT called if the payload is a `string`, a `Buffer`, a
170
- `stream`, or `null`.
169
+ > 🛈 Note: The hook is NOT called if the payload is a `string`, a `Buffer`, a
170
+ > `stream`, or `null`.
171
171
 
172
172
  ### onError
173
173
  ```js
@@ -196,8 +196,8 @@ user
196
196
  *(Note that the default error handler always sends the error back to the
197
197
  user)*.
198
198
 
199
- **Notice:** unlike the other hooks, passing an error to the `done` function is not
200
- supported.
199
+ > 🛈 Note: Unlike the other hooks, passing an error to the `done` function is not
200
+ > supported.
201
201
 
202
202
  ### onSend
203
203
  If you are using the `onSend` hook, you can change the payload. For example:
@@ -233,8 +233,8 @@ fastify.addHook('onSend', (request, reply, payload, done) => {
233
233
  > to `0`, whereas the `Content-Length` header will not be set if the payload is
234
234
  > `null`.
235
235
 
236
- Note: If you change the payload, you may only change it to a `string`, a
237
- `Buffer`, a `stream`, a `ReadableStream`, a `Response`, or `null`.
236
+ > 🛈 Note: If you change the payload, you may only change it to a `string`, a
237
+ > `Buffer`, a `stream`, a `ReadableStream`, a `Response`, or `null`.
238
238
 
239
239
 
240
240
  ### onResponse
@@ -256,8 +256,8 @@ The `onResponse` hook is executed when a response has been sent, so you will not
256
256
  be able to send more data to the client. It can however be useful for sending
257
257
  data to external services, for example, to gather statistics.
258
258
 
259
- **Note:** setting `disableRequestLogging` to `true` will disable any error log
260
- inside the `onResponse` hook. In this case use `try - catch` to log errors.
259
+ > 🛈 Note: Setting `disableRequestLogging` to `true` will disable any error log
260
+ > inside the `onResponse` hook. In this case use `try - catch` to log errors.
261
261
 
262
262
  ### onTimeout
263
263
 
@@ -298,7 +298,8 @@ The `onRequestAbort` hook is executed when a client closes the connection before
298
298
  the entire request has been processed. Therefore, you will not be able to send
299
299
  data to the client.
300
300
 
301
- **Notice:** client abort detection is not completely reliable. See: [`Detecting-When-Clients-Abort.md`](../Guides/Detecting-When-Clients-Abort.md)
301
+ > 🛈 Note: Client abort detection is not completely reliable.
302
+ > See: [`Detecting-When-Clients-Abort.md`](../Guides/Detecting-When-Clients-Abort.md)
302
303
 
303
304
  ### Manage Errors from a hook
304
305
  If you get an error during the execution of your hook, just pass it to `done()`
@@ -451,8 +452,8 @@ fastify.addHook('onListen', async function () {
451
452
  })
452
453
  ```
453
454
 
454
- > **Note**
455
- > This hook will not run when the server is started using `fastify.inject()` or `fastify.ready()`
455
+ > 🛈 Note: This hook will not run when the server is started using
456
+ > fastify.inject()` or `fastify.ready()`.
456
457
 
457
458
  ### onClose
458
459
  <a id="on-close"></a>
@@ -575,8 +576,8 @@ This hook can be useful if you are developing a plugin that needs to know when a
575
576
  plugin context is formed, and you want to operate in that specific context, thus
576
577
  this hook is encapsulated.
577
578
 
578
- **Note:** This hook will not be called if a plugin is wrapped inside
579
- [`fastify-plugin`](https://github.com/fastify/fastify-plugin).
579
+ > 🛈 Note: This hook will not be called if a plugin is wrapped inside
580
+ > [`fastify-plugin`](https://github.com/fastify/fastify-plugin).
580
581
  ```js
581
582
  fastify.decorate('data', [])
582
583
 
@@ -773,7 +774,7 @@ fastify.route({
773
774
  })
774
775
  ```
775
776
 
776
- **Note**: both options also accept an array of functions.
777
+ > 🛈 Note: Both options also accept an array of functions.
777
778
 
778
779
  ## Using Hooks to Inject Custom Properties
779
780
  <a id="using-hooks-to-inject-custom-properties"></a>
@@ -860,7 +861,7 @@ channel.subscribe(function ({ fastify }) {
860
861
  })
861
862
  ```
862
863
 
863
- > **Note:** The TracingChannel class API is currently experimental and may undergo
864
+ > 🛈 Note: The TracingChannel class API is currently experimental and may undergo
864
865
  > breaking changes even in semver-patch releases of Node.js.
865
866
 
866
867
  Five other events are published on a per-request basis following the
@@ -1,8 +1,7 @@
1
1
  <h1 align="center">Fastify</h1>
2
2
 
3
3
  ## Long Term Support
4
-
5
- `<a id="lts"></a>`
4
+ <a id="lts"></a>
6
5
 
7
6
  Fastify's Long Term Support (LTS) is provided according to the schedule laid out
8
7
  in this document:
@@ -25,13 +24,11 @@ in this document:
25
24
  and verified against alternative runtimes that are compatible with Node.js.
26
25
  The maintenance teams of these alternative runtimes are responsible for ensuring
27
26
  and guaranteeing these tests work properly.
28
- 1. [N|Solid](https://docs.nodesource.com/nsolid), maintained by NodeSource,
29
- commits to testing and verifying each Fastify major release against the N|Solid
30
- LTS versions that are current at the time of the Fastify release.
31
- NodeSource guarantees that Fastify will be compatible and function correctly
32
- with N|Solid, aligning with the support and compatibility scope of the N|Solid
33
- LTS versions available at the time of the Fastify release.
34
- This ensures users of N|Solid can confidently use Fastify.
27
+ 1. [N|Solid](https://docs.nodesource.com/docs/product_suite) tests and
28
+ verifies each Fastify major release against current N|Solid LTS versions.
29
+ NodeSource ensures Fastify compatibility with N|Solid, aligning with the
30
+ support scope of N|Solid LTS versions at the time of the Fastify release.
31
+ This guarantees N|Solid users can confidently use Fastify.
35
32
 
36
33
  A "month" is defined as 30 consecutive days.
37
34
 
@@ -41,12 +38,12 @@ A "month" is defined as 30 consecutive days.
41
38
  > occasions where we need to release breaking changes as a _minor_ version
42
39
  > release. Such changes will _always_ be noted in the [release
43
40
  > notes](https://github.com/fastify/fastify/releases).
44
- >
41
+ >
45
42
  > To avoid automatically receiving breaking security updates it is possible to
46
43
  > use the tilde (`~`) range qualifier. For example, to get patches for the 3.15
47
44
  > release, and avoid automatically updating to the 3.16 release, specify the
48
45
  > dependency as `"fastify": "~3.15.x"`. This will leave your application
49
- > vulnerable, so please use with caution.
46
+ > vulnerable, so please use it with caution.
50
47
 
51
48
  ### Security Support Beyond LTS
52
49
 
@@ -55,8 +52,7 @@ OpenJS Ecosystem Sustainability Program for versions of Fastify that are EOL.
55
52
  For more information, see their [Never Ending Support][hd-link] service.
56
53
 
57
54
  ### Schedule
58
-
59
- `<a id="lts-schedule"></a>`
55
+ <a id="lts-schedule"></a>
60
56
 
61
57
  | Version | Release Date | End Of LTS Date | Node.js | Nsolid(Node) |
62
58
  | :------ | :----------- | :-------------- | :----------------- | :------------- |
@@ -67,8 +63,7 @@ For more information, see their [Never Ending Support][hd-link] service.
67
63
  | 5.0.0 | 2024-09-17 | TBD | 20, 22 | v5(20) |
68
64
 
69
65
  ### CI tested operating systems
70
-
71
- `<a id="supported-os"></a>`
66
+ <a id="supported-os"></a>
72
67
 
73
68
  Fastify uses GitHub Actions for CI testing, please refer to [GitHub&#39;s
74
69
  documentation regarding workflow
@@ -3,12 +3,11 @@
3
3
  ## Lifecycle
4
4
  <a id="lifecycle"></a>
5
5
 
6
- Following the schema of the internal lifecycle of Fastify.
6
+ This schema shows the internal lifecycle of Fastify.
7
7
 
8
- On the right branch of every section there is the next phase of the lifecycle,
9
- on the left branch there is the corresponding error code that will be generated
10
- if the parent throws an error *(note that all the errors are automatically
11
- handled by Fastify)*.
8
+ The right branch of each section shows the next phase of the lifecycle. The left
9
+ branch shows the corresponding error code generated if the parent throws an
10
+ error. All errors are automatically handled by Fastify.
12
11
 
13
12
  ```
14
13
  Incoming Request
@@ -42,26 +41,23 @@ Incoming Request
42
41
  └─▶ onResponse Hook
43
42
  ```
44
43
 
45
- At any point before or during the `User Handler`, `reply.hijack()` can be called
46
- to prevent Fastify from:
47
- - Running all the following hooks and user handler
48
- - Sending the response automatically
44
+ Before or during the `User Handler`, `reply.hijack()` can be called to:
45
+ - Prevent Fastify from running subsequent hooks and the user handler
46
+ - Prevent Fastify from sending the response automatically
49
47
 
50
- NB (*): If `reply.raw` is used to send a response back to the user, `onResponse`
51
- hooks will still be executed
48
+ If `reply.raw` is used to send a response, `onResponse` hooks will still
49
+ be executed.
52
50
 
53
51
  ## Reply Lifecycle
54
52
  <a id="reply-lifecycle"></a>
55
53
 
56
- Whenever the user handles the request, the result may be:
54
+ When the user handles the request, the result may be:
57
55
 
58
- - in async handler: it returns a payload
59
- - in async handler: it throws an `Error`
60
- - in sync handler: it sends a payload
61
- - in sync handler: it sends an `Error` instance
56
+ - In an async handler: it returns a payload or throws an `Error`
57
+ - In a sync handler: it sends a payload or an `Error` instance
62
58
 
63
- If the reply was hijacked, we skip all the below steps. Otherwise, when it is
64
- being submitted, the data flow performed is the following:
59
+ If the reply was hijacked, all subsequent steps are skipped. Otherwise, when
60
+ submitted, the data flow is as follows:
65
61
 
66
62
  ```
67
63
  ★ schema validation Error
@@ -81,9 +77,8 @@ being submitted, the data flow performed is the following:
81
77
  └─▶ reply sent
82
78
  ```
83
79
 
84
- Note: `reply sent` means that the JSON payload will be serialized by:
85
-
86
- - the [reply serialized](./Server.md#setreplyserializer) if set
87
- - or by the [serializer compiler](./Server.md#setserializercompiler) when a JSON
88
- schema has been set for the returning HTTP status code
89
- - or by the default `JSON.stringify` function
80
+ `reply sent` means the JSON payload will be serialized by one of the following:
81
+ - The [reply serializer](./Server.md#setreplyserializer) if set
82
+ - The [serializer compiler](./Server.md#setserializercompiler) if a JSON schema
83
+ is set for the HTTP status code
84
+ - The default `JSON.stringify` function