fastify 5.6.2 → 5.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -33
- package/SECURITY.md +45 -7
- package/SPONSORS.md +1 -1
- package/build/build-validation.js +1 -2
- package/build/sync-version.js +0 -1
- package/docs/Guides/Detecting-When-Clients-Abort.md +1 -1
- package/docs/Guides/Ecosystem.md +12 -15
- package/docs/Guides/Migration-Guide-V4.md +2 -1
- package/docs/Guides/Migration-Guide-V5.md +9 -0
- package/docs/Guides/Serverless.md +25 -7
- package/docs/Guides/Testing.md +2 -2
- package/docs/Reference/Decorators.md +4 -3
- package/docs/Reference/Encapsulation.md +2 -2
- package/docs/Reference/Logging.md +4 -0
- package/docs/Reference/Plugins.md +2 -2
- package/docs/Reference/Principles.md +2 -2
- package/docs/Reference/Reply.md +3 -2
- package/docs/Reference/Server.md +35 -4
- package/docs/Reference/TypeScript.md +2 -1
- package/docs/Reference/Validation-and-Serialization.md +7 -1
- package/examples/benchmark/webstream.js +27 -0
- package/fastify.d.ts +16 -21
- package/fastify.js +14 -9
- package/lib/config-validator.js +189 -223
- package/lib/error-handler.js +2 -5
- package/lib/error-status.js +14 -0
- package/lib/four-oh-four.js +2 -1
- package/lib/handle-request.js +6 -1
- package/lib/reply.js +53 -3
- package/lib/route.js +26 -12
- package/lib/schema-controller.js +2 -2
- package/lib/wrap-thenable.js +3 -0
- package/package.json +4 -4
- package/test/404s.test.js +69 -0
- package/test/diagnostics-channel/error-status.test.js +84 -0
- package/test/internals/schema-controller-perf.test.js +40 -0
- package/test/issue-4959.test.js +34 -9
- package/test/listen.1.test.js +9 -1
- package/test/logger/logging.test.js +38 -1
- package/test/router-options.test.js +169 -0
- package/test/server.test.js +4 -1
- package/test/types/fastify.test-d.ts +28 -7
- package/test/types/instance.test-d.ts +29 -21
- package/test/types/reply.test-d.ts +55 -4
- package/test/types/type-provider.test-d.ts +6 -6
- package/test/web-api.test.js +136 -0
- package/types/instance.d.ts +1 -1
- package/types/reply.d.ts +2 -2
- package/types/type-provider.d.ts +16 -0
- package/.vscode/settings.json +0 -22
- package/test/decorator-namespace.test._js_ +0 -30
package/README.md
CHANGED
|
@@ -260,7 +260,8 @@ application. You should __always__ benchmark if performance matters to you.
|
|
|
260
260
|
Please visit [Fastify help](https://github.com/fastify/help) to view prior
|
|
261
261
|
support issues and to ask new support questions.
|
|
262
262
|
|
|
263
|
-
Version 3 of Fastify and lower are EOL and will not receive any security or bug
|
|
263
|
+
Version 3 of Fastify and lower are EOL and will not receive any security or bug
|
|
264
|
+
fixes.
|
|
264
265
|
|
|
265
266
|
Fastify's partner, HeroDevs, provides commercial security fixes for all
|
|
266
267
|
unsupported versions at [https://herodevs.com/support/fastify-nes][hd-link].
|
|
@@ -280,70 +281,70 @@ listed in alphabetical order.
|
|
|
280
281
|
|
|
281
282
|
**Lead Maintainers:**
|
|
282
283
|
* [__Matteo Collina__](https://github.com/mcollina),
|
|
283
|
-
<https://
|
|
284
|
+
<https://x.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
|
|
284
285
|
* [__Tomas Della Vedova__](https://github.com/delvedor),
|
|
285
|
-
<https://
|
|
286
|
+
<https://x.com/delvedor>, <https://www.npmjs.com/~delvedor>
|
|
286
287
|
* [__KaKa Ng__](https://github.com/climba03003),
|
|
287
288
|
<https://www.npmjs.com/~climba03003>
|
|
288
289
|
* [__Manuel Spigolon__](https://github.com/eomm),
|
|
289
|
-
<https://
|
|
290
|
+
<https://x.com/manueomm>, <https://www.npmjs.com/~eomm>
|
|
290
291
|
* [__James Sumners__](https://github.com/jsumners),
|
|
291
|
-
<https://
|
|
292
|
+
<https://x.com/jsumners79>, <https://www.npmjs.com/~jsumners>
|
|
292
293
|
|
|
293
294
|
### Fastify Core team
|
|
294
295
|
* [__Aras Abbasi__](https://github.com/uzlopak),
|
|
295
296
|
<https://www.npmjs.com/~uzlopak>
|
|
296
297
|
* [__Harry Brundage__](https://github.com/airhorns/),
|
|
297
|
-
<https://
|
|
298
|
+
<https://x.com/harrybrundage>, <https://www.npmjs.com/~airhorns>
|
|
298
299
|
* [__Matteo Collina__](https://github.com/mcollina),
|
|
299
|
-
<https://
|
|
300
|
+
<https://x.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
|
|
300
301
|
* [__Gürgün Dayıoğlu__](https://github.com/gurgunday),
|
|
301
302
|
<https://www.npmjs.com/~gurgunday>
|
|
302
303
|
* [__Tomas Della Vedova__](https://github.com/delvedor),
|
|
303
|
-
<https://
|
|
304
|
+
<https://x.com/delvedor>, <https://www.npmjs.com/~delvedor>
|
|
304
305
|
* [__Carlos Fuentes__](https://github.com/metcoder95),
|
|
305
|
-
<https://
|
|
306
|
+
<https://x.com/metcoder95>, <https://www.npmjs.com/~metcoder95>
|
|
306
307
|
* [__Vincent Le Goff__](https://github.com/zekth)
|
|
307
308
|
* [__Luciano Mammino__](https://github.com/lmammino),
|
|
308
|
-
<https://
|
|
309
|
+
<https://x.com/loige>, <https://www.npmjs.com/~lmammino>
|
|
309
310
|
* [__Jean Michelet__](https://github.com/jean-michelet),
|
|
310
311
|
<https://www.npmjs.com/~jean-michelet>
|
|
311
312
|
* [__KaKa Ng__](https://github.com/climba03003),
|
|
312
313
|
<https://www.npmjs.com/~climba03003>
|
|
313
314
|
* [__Luis Orbaiceta__](https://github.com/luisorbaiceta),
|
|
314
|
-
<https://
|
|
315
|
+
<https://x.com/luisorbai>, <https://www.npmjs.com/~luisorbaiceta>
|
|
315
316
|
* [__Maksim Sinik__](https://github.com/fox1t),
|
|
316
|
-
<https://
|
|
317
|
+
<https://x.com/maksimsinik>, <https://www.npmjs.com/~fox1t>
|
|
317
318
|
* [__Manuel Spigolon__](https://github.com/eomm),
|
|
318
|
-
<https://
|
|
319
|
+
<https://x.com/manueomm>, <https://www.npmjs.com/~eomm>
|
|
319
320
|
* [__James Sumners__](https://github.com/jsumners),
|
|
320
|
-
<https://
|
|
321
|
+
<https://x.com/jsumners79>, <https://www.npmjs.com/~jsumners>
|
|
321
322
|
|
|
322
323
|
### Fastify Plugins team
|
|
323
324
|
* [__Harry Brundage__](https://github.com/airhorns/),
|
|
324
|
-
<https://
|
|
325
|
+
<https://x.com/harrybrundage>, <https://www.npmjs.com/~airhorns>
|
|
325
326
|
* [__Simone Busoli__](https://github.com/simoneb),
|
|
326
|
-
<https://
|
|
327
|
+
<https://x.com/simonebu>, <https://www.npmjs.com/~simoneb>
|
|
327
328
|
* [__Dan Castillo__](https://github.com/dancastillo),
|
|
328
329
|
<https://www.npmjs.com/~dancastillo>
|
|
329
330
|
* [__Matteo Collina__](https://github.com/mcollina),
|
|
330
|
-
<https://
|
|
331
|
+
<https://x.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
|
|
331
332
|
* [__Gürgün Dayıoğlu__](https://github.com/gurgunday),
|
|
332
333
|
<https://www.npmjs.com/~gurgunday>
|
|
333
334
|
* [__Tomas Della Vedova__](https://github.com/delvedor),
|
|
334
|
-
<https://
|
|
335
|
+
<https://x.com/delvedor>, <https://www.npmjs.com/~delvedor>
|
|
335
336
|
* [__Carlos Fuentes__](https://github.com/metcoder95),
|
|
336
|
-
<https://
|
|
337
|
+
<https://x.com/metcoder95>, <https://www.npmjs.com/~metcoder95>
|
|
337
338
|
* [__Vincent Le Goff__](https://github.com/zekth)
|
|
338
339
|
* [__Jean Michelet__](https://github.com/jean-michelet),
|
|
339
340
|
<https://www.npmjs.com/~jean-michelet>
|
|
340
341
|
* [__KaKa Ng__](https://github.com/climba03003),
|
|
341
342
|
<https://www.npmjs.com/~climba03003>
|
|
342
343
|
* [__Maksim Sinik__](https://github.com/fox1t),
|
|
343
|
-
<https://
|
|
344
|
+
<https://x.com/maksimsinik>, <https://www.npmjs.com/~fox1t>
|
|
344
345
|
* [__Frazer Smith__](https://github.com/Fdawgs), <https://www.npmjs.com/~fdawgs>
|
|
345
346
|
* [__Manuel Spigolon__](https://github.com/eomm),
|
|
346
|
-
<https://
|
|
347
|
+
<https://x.com/manueomm>, <https://www.npmjs.com/~eomm>
|
|
347
348
|
|
|
348
349
|
### Emeritus Contributors
|
|
349
350
|
Great contributors to a specific area of the Fastify ecosystem will be invited
|
|
@@ -351,32 +352,32 @@ to join this group by Lead Maintainers when they decide to step down from the
|
|
|
351
352
|
active contributor's group.
|
|
352
353
|
|
|
353
354
|
* [__Tommaso Allevi__](https://github.com/allevo),
|
|
354
|
-
<https://
|
|
355
|
+
<https://x.com/allevitommaso>, <https://www.npmjs.com/~allevo>
|
|
355
356
|
* [__Ethan Arrowood__](https://github.com/Ethan-Arrowood/),
|
|
356
|
-
<https://
|
|
357
|
+
<https://x.com/arrowoodtech>, <https://www.npmjs.com/~ethan_arrowood>
|
|
357
358
|
* [__Çağatay Çalı__](https://github.com/cagataycali),
|
|
358
|
-
<https://
|
|
359
|
+
<https://x.com/cagataycali>, <https://www.npmjs.com/~cagataycali>
|
|
359
360
|
* [__David Mark Clements__](https://github.com/davidmarkclements),
|
|
360
|
-
<https://
|
|
361
|
+
<https://x.com/davidmarkclem>,
|
|
361
362
|
<https://www.npmjs.com/~davidmarkclements>
|
|
362
|
-
* [__dalisoft__](https://github.com/dalisoft), <https://
|
|
363
|
+
* [__dalisoft__](https://github.com/dalisoft), <https://x.com/dalisoft>,
|
|
363
364
|
<https://www.npmjs.com/~dalisoft>
|
|
364
365
|
* [__Dustin Deus__](https://github.com/StarpTech),
|
|
365
|
-
<https://
|
|
366
|
+
<https://x.com/dustindeus>, <https://www.npmjs.com/~starptech>
|
|
366
367
|
* [__Denis Fäcke__](https://github.com/SerayaEryn),
|
|
367
|
-
<https://
|
|
368
|
+
<https://x.com/serayaeryn>, <https://www.npmjs.com/~serayaeryn>
|
|
368
369
|
* [__Rafael Gonzaga__](https://github.com/rafaelgss),
|
|
369
|
-
<https://
|
|
370
|
+
<https://x.com/_rafaelgss>, <https://www.npmjs.com/~rafaelgss>
|
|
370
371
|
* [__Trivikram Kamat__](https://github.com/trivikr),
|
|
371
|
-
<https://
|
|
372
|
+
<https://x.com/trivikram>, <https://www.npmjs.com/~trivikr>
|
|
372
373
|
* [__Ayoub El Khattabi__](https://github.com/AyoubElk),
|
|
373
|
-
<https://
|
|
374
|
+
<https://x.com/ayoubelkh>, <https://www.npmjs.com/~ayoubelk>
|
|
374
375
|
* [__Cemre Mengu__](https://github.com/cemremengu),
|
|
375
|
-
<https://
|
|
376
|
+
<https://x.com/cemremengu>, <https://www.npmjs.com/~cemremengu>
|
|
376
377
|
* [__Salman Mitha__](https://github.com/salmanm),
|
|
377
378
|
<https://www.npmjs.com/~salmanm>
|
|
378
379
|
* [__Nathan Woltman__](https://github.com/nwoltman),
|
|
379
|
-
<https://
|
|
380
|
+
<https://x.com/NathanWoltman>, <https://www.npmjs.com/~nwoltman>
|
|
380
381
|
|
|
381
382
|
## Hosted by
|
|
382
383
|
|
package/SECURITY.md
CHANGED
|
@@ -3,6 +3,46 @@
|
|
|
3
3
|
This document describes the management of vulnerabilities for the Fastify
|
|
4
4
|
project and its official plugins.
|
|
5
5
|
|
|
6
|
+
## Threat Model
|
|
7
|
+
|
|
8
|
+
Fastify's threat model extends the
|
|
9
|
+
[Node.js threat model](https://github.com/nodejs/node/blob/main/SECURITY.md#the-nodejs-threat-model).
|
|
10
|
+
|
|
11
|
+
**Trusted:** Application code (plugins, handlers, hooks, schemas), configuration,
|
|
12
|
+
and the runtime environment.
|
|
13
|
+
|
|
14
|
+
**Untrusted:** All network input (HTTP headers, body, query strings, URL
|
|
15
|
+
parameters).
|
|
16
|
+
|
|
17
|
+
### Examples of Vulnerabilities
|
|
18
|
+
|
|
19
|
+
- Parsing flaws that bypass validation or security controls
|
|
20
|
+
- DoS through malformed input to Fastify's core
|
|
21
|
+
- Bypasses of built-in protections (prototype poisoning, schema validation)
|
|
22
|
+
|
|
23
|
+
### Examples of Non-Vulnerabilities
|
|
24
|
+
|
|
25
|
+
The following are **not** considered vulnerabilities in Fastify:
|
|
26
|
+
|
|
27
|
+
- **Application code vulnerabilities**: XSS, SQL injection, or other flaws in
|
|
28
|
+
user-written route handlers, hooks, or plugins
|
|
29
|
+
- **Malicious application code**: Issues caused by intentionally malicious
|
|
30
|
+
plugins or handlers (application code is trusted)
|
|
31
|
+
- **Validation schema issues**: Weak or incorrect schemas provided by developers
|
|
32
|
+
(schemas are trusted)
|
|
33
|
+
- **ReDoS in user patterns**: Regular expression DoS in user-provided regex
|
|
34
|
+
patterns for routes or validation
|
|
35
|
+
- **Missing security features**: Lack of rate limiting, authentication, or
|
|
36
|
+
authorization (these are application-level concerns)
|
|
37
|
+
- **Configuration mistakes**: Security issues arising from developer
|
|
38
|
+
misconfiguration (configuration is trusted)
|
|
39
|
+
- **Third-party dependencies**: Vulnerabilities in npm packages used by the
|
|
40
|
+
application (not Fastify core dependencies)
|
|
41
|
+
- **Resource exhaustion from handlers**: DoS caused by expensive operations in
|
|
42
|
+
user route handlers
|
|
43
|
+
- **Information disclosure by design**: Exposing error details or stack traces
|
|
44
|
+
explicitly enabled via configuration options
|
|
45
|
+
|
|
6
46
|
## Reporting vulnerabilities
|
|
7
47
|
|
|
8
48
|
Individuals who find potential vulnerabilities in Fastify are invited to
|
|
@@ -137,13 +177,13 @@ work as a member of the Fastify Core team.
|
|
|
137
177
|
### Members
|
|
138
178
|
|
|
139
179
|
* [__Matteo Collina__](https://github.com/mcollina),
|
|
140
|
-
<https://
|
|
180
|
+
<https://x.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
|
|
141
181
|
* [__Tomas Della Vedova__](https://github.com/delvedor),
|
|
142
|
-
<https://
|
|
182
|
+
<https://x.com/delvedor>, <https://www.npmjs.com/~delvedor>
|
|
143
183
|
* [__Vincent Le Goff__](https://github.com/zekth)
|
|
144
184
|
* [__KaKa Ng__](https://github.com/climba03003)
|
|
145
185
|
* [__James Sumners__](https://github.com/jsumners),
|
|
146
|
-
<https://
|
|
186
|
+
<https://x.com/jsumners79>, <https://www.npmjs.com/~jsumners>
|
|
147
187
|
|
|
148
188
|
## OpenSSF CII Best Practices
|
|
149
189
|
|
|
@@ -155,11 +195,9 @@ There are three “tiers”: passing, silver, and gold.
|
|
|
155
195
|
We meet 100% of the “passing” criteria.
|
|
156
196
|
|
|
157
197
|
### Silver
|
|
158
|
-
We meet 87% of the
|
|
198
|
+
We meet 87% of the "silver" criteria. The gaps are as follows:
|
|
159
199
|
- we do not have a DCO or a CLA process for contributions.
|
|
160
|
-
- we do not currently document
|
|
161
|
-
“what the user can and cannot expect in terms of security” for our project.
|
|
162
|
-
- we do not currently document ”the architecture (aka high-level design)”
|
|
200
|
+
- we do not currently document "the architecture (aka high-level design)"
|
|
163
201
|
for our project.
|
|
164
202
|
|
|
165
203
|
### Gold
|
package/SPONSORS.md
CHANGED
|
@@ -98,7 +98,6 @@ const schema = {
|
|
|
98
98
|
ignoreTrailingSlash: { type: 'boolean', default: defaultInitOptions.ignoreTrailingSlash },
|
|
99
99
|
ignoreDuplicateSlashes: { type: 'boolean', default: defaultInitOptions.ignoreDuplicateSlashes },
|
|
100
100
|
disableRequestLogging: {
|
|
101
|
-
type: 'boolean',
|
|
102
101
|
default: false
|
|
103
102
|
},
|
|
104
103
|
maxParamLength: { type: 'integer', default: defaultInitOptions.maxParamLength },
|
|
@@ -112,7 +111,7 @@ const schema = {
|
|
|
112
111
|
useSemicolonDelimiter: { type: 'boolean', default: defaultInitOptions.useSemicolonDelimiter },
|
|
113
112
|
routerOptions: {
|
|
114
113
|
type: 'object',
|
|
115
|
-
additionalProperties:
|
|
114
|
+
additionalProperties: true,
|
|
116
115
|
properties: {
|
|
117
116
|
ignoreTrailingSlash: { type: 'boolean', default: defaultInitOptions.routerOptions.ignoreTrailingSlash },
|
|
118
117
|
ignoreDuplicateSlashes: { type: 'boolean', default: defaultInitOptions.routerOptions.ignoreDuplicateSlashes },
|
package/build/sync-version.js
CHANGED
|
@@ -9,4 +9,3 @@ const { version } = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'packa
|
|
|
9
9
|
const fastifyJs = path.join(__dirname, '..', 'fastify.js')
|
|
10
10
|
|
|
11
11
|
fs.writeFileSync(fastifyJs, fs.readFileSync(fastifyJs).toString('utf8').replace(/const\s*VERSION\s*=.*/, `const VERSION = '${version}'`))
|
|
12
|
-
console.log(`Synchronized fastify.js VERSION to ${version}`)
|
|
@@ -81,7 +81,7 @@ start()
|
|
|
81
81
|
Our code is setting up a Fastify server which includes the following
|
|
82
82
|
functionality:
|
|
83
83
|
|
|
84
|
-
- Accepting requests at http://localhost:3000
|
|
84
|
+
- Accepting requests at `http://localhost:3000`, with a 3 second delayed response
|
|
85
85
|
of `{ ok: true }`.
|
|
86
86
|
- An onRequest hook that triggers when every request is received.
|
|
87
87
|
- Logic that triggers in the hook when the request is closed.
|
package/docs/Guides/Ecosystem.md
CHANGED
|
@@ -182,13 +182,8 @@ section.
|
|
|
182
182
|
close the server gracefully on `SIGINT` and `SIGTERM` signals.
|
|
183
183
|
- [`@eropple/fastify-openapi3`](https://github.com/eropple/fastify-openapi3) Provides
|
|
184
184
|
easy, developer-friendly OpenAPI 3.1 specs + doc explorer based on your routes.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
great TypeScript support + built-in adapters for common ORMs/databases (Firebase,
|
|
188
|
-
Prisma Client, Postgres (wip), InMemory) and you can easily make your own adapter!
|
|
189
|
-
- [`@ethicdevs/fastify-git-server`](https://github.com/EthicDevs/fastify-git-server)
|
|
190
|
-
A plugin to easily create git server and make one/many Git repositories available
|
|
191
|
-
for clone/fetch/push through the standard `git` (over http) commands.
|
|
185
|
+
|
|
186
|
+
|
|
192
187
|
- [`@exortek/fastify-mongo-sanitize`](https://github.com/ExorTek/fastify-mongo-sanitize)
|
|
193
188
|
A Fastify plugin that protects against No(n)SQL injection by sanitizing data.
|
|
194
189
|
- [`@exortek/remix-fastify`](https://github.com/ExorTek/remix-fastify)
|
|
@@ -246,6 +241,9 @@ section.
|
|
|
246
241
|
request IDs into your logs.
|
|
247
242
|
- [`electron-server`](https://github.com/anonrig/electron-server) A plugin for
|
|
248
243
|
using Fastify without the need of consuming a port on Electron apps.
|
|
244
|
+
- [`elements-fastify`](https://github.com/rohitsoni007/elements-fastify) Fastify
|
|
245
|
+
Plugin for Stoplight Elements API Documentation using
|
|
246
|
+
openapi swagger json yml.
|
|
249
247
|
- [`fast-water`](https://github.com/tswayne/fast-water) A Fastify plugin for
|
|
250
248
|
waterline. Decorates Fastify with waterline models.
|
|
251
249
|
- [`fastify-204`](https://github.com/Shiva127/fastify-204) Fastify plugin that
|
|
@@ -373,7 +371,7 @@ section.
|
|
|
373
371
|
- [`fastify-feature-flags`](https://gitlab.com/m03geek/fastify-feature-flags)
|
|
374
372
|
Fastify feature flags plugin with multiple providers support (e.g. env,
|
|
375
373
|
[config](https://lorenwest.github.io/node-config/),
|
|
376
|
-
[unleash](https://
|
|
374
|
+
[unleash](https://github.com/Unleash/unleash)).
|
|
377
375
|
- [`fastify-file-routes`](https://github.com/spa5k/fastify-file-routes) Get
|
|
378
376
|
Next.js based file system routing into fastify.
|
|
379
377
|
- [`fastify-file-upload`](https://github.com/huangang/fastify-file-upload)
|
|
@@ -524,10 +522,7 @@ middlewares into Fastify plugins
|
|
|
524
522
|
Add `additionalProperties: false` by default to your JSON Schemas.
|
|
525
523
|
- [`fastify-no-icon`](https://github.com/jsumners/fastify-no-icon) Plugin to
|
|
526
524
|
eliminate thrown errors for `/favicon.ico` requests.
|
|
527
|
-
|
|
528
|
-
Plugin to normalize the request and reply to the Express version 4.x request
|
|
529
|
-
and response, which allows use of middleware, like swagger-stats, that was
|
|
530
|
-
originally written for Express.
|
|
525
|
+
|
|
531
526
|
- [`fastify-now`](https://github.com/yonathan06/fastify-now) Structure your
|
|
532
527
|
endpoints in a folder and load them dynamically with Fastify.
|
|
533
528
|
- [`fastify-nuxtjs`](https://github.com/gomah/fastify-nuxtjs) Vue server-side
|
|
@@ -571,8 +566,8 @@ middlewares into Fastify plugins
|
|
|
571
566
|
custom permission checks.
|
|
572
567
|
- [`fastify-piscina`](https://github.com/piscinajs/fastify-piscina) A worker
|
|
573
568
|
thread pool plugin using [Piscina](https://github.com/piscinajs/piscina).
|
|
574
|
-
- [`fastify-polyglot`](https://github.com/beliven-it/fastify-polyglot) A plugin
|
|
575
|
-
handle i18n using
|
|
569
|
+
- [`fastify-polyglot`](https://github.com/beliven-it/fastify-polyglot) A plugin
|
|
570
|
+
to handle i18n using
|
|
576
571
|
[node-polyglot](https://www.npmjs.com/package/node-polyglot).
|
|
577
572
|
- [`fastify-postgraphile`](https://github.com/alemagio/fastify-postgraphile)
|
|
578
573
|
Plugin to integrate [PostGraphile](https://www.graphile.org/postgraphile/) in
|
|
@@ -646,6 +641,8 @@ middlewares into Fastify plugins
|
|
|
646
641
|
- [`fastify-server-session`](https://github.com/jsumners/fastify-server-session)
|
|
647
642
|
A session plugin with support for arbitrary backing caches via
|
|
648
643
|
`fastify-caching`.
|
|
644
|
+
- [`fastify-ses-mailer`](https://github.com/KaranHotwani/fastify-ses-mailer) A
|
|
645
|
+
Fastify plugin for sending emails via AWS SES using AWS SDK v3.
|
|
649
646
|
- [`fastify-shared-schema`](https://github.com/Adibla/fastify-shared-schema) Plugin
|
|
650
647
|
for sharing schemas between different routes.
|
|
651
648
|
- [`fastify-slonik`](https://github.com/Unbuttun/fastify-slonik) Fastify Slonik
|
|
@@ -687,7 +684,7 @@ middlewares into Fastify plugins
|
|
|
687
684
|
- [`fastify-type-provider-effect-schema`](https://github.com/daotl/fastify-type-provider-effect-schema)
|
|
688
685
|
Fastify
|
|
689
686
|
[type provider](https://fastify.dev/docs/latest/Reference/Type-Providers/)
|
|
690
|
-
for [@effect/schema](https://github.com/
|
|
687
|
+
for [@effect/schema](https://github.com/Effect-TS/effect).
|
|
691
688
|
- [`fastify-type-provider-zod`](https://github.com/turkerdev/fastify-type-provider-zod)
|
|
692
689
|
Fastify
|
|
693
690
|
[type provider](https://fastify.dev/docs/latest/Reference/Type-Providers/)
|
|
@@ -109,7 +109,8 @@ argument from your router handler.
|
|
|
109
109
|
### `exposeHeadRoutes` true by default
|
|
110
110
|
|
|
111
111
|
Starting with v4, every `GET` route will create a sibling `HEAD` route.
|
|
112
|
-
You can revert this behavior by setting `exposeHeadRoutes: false` in the server
|
|
112
|
+
You can revert this behavior by setting `exposeHeadRoutes: false` in the server
|
|
113
|
+
options.
|
|
113
114
|
|
|
114
115
|
### Synchronous route definitions ([#2954](https://github.com/fastify/fastify/pull/2954))
|
|
115
116
|
|
|
@@ -545,6 +545,15 @@ for more information.
|
|
|
545
545
|
This was already deprecated in v4 as `FSTDEP014`,
|
|
546
546
|
so you should have already updated your code.
|
|
547
547
|
|
|
548
|
+
### `time` and `date-time` formats enforce timezone
|
|
549
|
+
|
|
550
|
+
The updated AJV compiler updates `ajv-formats` which now
|
|
551
|
+
enforce the use of timezone in `time` and `date-time` format.
|
|
552
|
+
A workaround is to use `iso-time` and `iso-date-time` formats
|
|
553
|
+
which support an optional timezone for backwards compatibility.
|
|
554
|
+
See the
|
|
555
|
+
[full discussion](https://github.com/fastify/fluent-json-schema/issues/267).
|
|
556
|
+
|
|
548
557
|
## New Features
|
|
549
558
|
|
|
550
559
|
### Diagnostic Channel support
|
|
@@ -303,10 +303,10 @@ const fastifyApp = async (request, reply) => {
|
|
|
303
303
|
|
|
304
304
|
### Add Custom `contentTypeParser` to Fastify instance and define endpoints
|
|
305
305
|
|
|
306
|
-
Firebase Function's HTTP layer already parses the request
|
|
307
|
-
|
|
308
|
-
to the raw body, unparsed, which is useful for calculating
|
|
309
|
-
|
|
306
|
+
Firebase Function's HTTP layer already parses the request and makes a JSON
|
|
307
|
+
payload available through the property `payload.body` below. It also provides
|
|
308
|
+
access to the raw body, unparsed, which is useful for calculating request
|
|
309
|
+
signatures to validate HTTP webhooks.
|
|
310
310
|
|
|
311
311
|
Add as follows to the `registerRoutes()` function:
|
|
312
312
|
|
|
@@ -332,6 +332,24 @@ async function registerRoutes (fastify) {
|
|
|
332
332
|
}
|
|
333
333
|
```
|
|
334
334
|
|
|
335
|
+
**Failing to add this `ContentTypeParser` may lead to the Fastify process
|
|
336
|
+
remaining stuck and not processing any other requests after receiving one with
|
|
337
|
+
the Content-Type `application/json`.**
|
|
338
|
+
|
|
339
|
+
When using Typescript, since the type of `payload` is a native `IncomingMessage`
|
|
340
|
+
that gets modified by Firebase, it won't be able to find the property
|
|
341
|
+
`payload.body`.
|
|
342
|
+
|
|
343
|
+
In order to suppress the error, you can use the following signature:
|
|
344
|
+
|
|
345
|
+
```ts
|
|
346
|
+
declare module 'http' {
|
|
347
|
+
interface IncomingMessage {
|
|
348
|
+
body?: unknown;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
335
353
|
### Export the function using Firebase onRequest
|
|
336
354
|
|
|
337
355
|
Final step is to export the Fastify app instance to Firebase's own
|
|
@@ -577,10 +595,10 @@ server-like concurrency with the autoscaling properties of traditional
|
|
|
577
595
|
serverless functions.
|
|
578
596
|
|
|
579
597
|
Get started with the
|
|
580
|
-
[Fastify
|
|
581
|
-
https://vercel.com/templates/
|
|
598
|
+
[Fastify template on Vercel](
|
|
599
|
+
https://vercel.com/templates/backend/fastify-on-vercel).
|
|
582
600
|
|
|
583
601
|
[Fluid compute](https://vercel.com/docs/functions/fluid-compute) currently
|
|
584
602
|
requires an explicit opt-in. Learn more about enabling Fluid compute
|
|
585
603
|
[here](
|
|
586
|
-
https://vercel.com/docs/functions/fluid-compute#how-to-enable-fluid-compute).
|
|
604
|
+
https://vercel.com/docs/functions/fluid-compute#how-to-enable-fluid-compute).
|
package/docs/Guides/Testing.md
CHANGED
|
@@ -353,8 +353,8 @@ Now you should be able to step through your test file (and the rest of
|
|
|
353
353
|
|
|
354
354
|
|
|
355
355
|
## Plugins
|
|
356
|
-
Let's `cd` into a fresh directory called 'testing-plugin-example' and type
|
|
357
|
-
-y` in our terminal.
|
|
356
|
+
Let's `cd` into a fresh directory called 'testing-plugin-example' and type
|
|
357
|
+
`npm init -y` in our terminal.
|
|
358
358
|
|
|
359
359
|
Run `npm i fastify fastify-plugin`
|
|
360
360
|
|
|
@@ -369,7 +369,8 @@ console.log(fastify.foo) // 'a getter'
|
|
|
369
369
|
#### `getDecorator(name)`
|
|
370
370
|
<a id="get-decorator"></a>
|
|
371
371
|
|
|
372
|
-
Used to retrieve an existing decorator from the Fastify instance, `Request`,
|
|
372
|
+
Used to retrieve an existing decorator from the Fastify instance, `Request`,
|
|
373
|
+
or `Reply`.
|
|
373
374
|
If the decorator is not defined, an `FST_ERR_DEC_UNDECLARED` error is thrown.
|
|
374
375
|
|
|
375
376
|
```js
|
|
@@ -399,7 +400,7 @@ fastify.register(async function (fastify) {
|
|
|
399
400
|
```
|
|
400
401
|
|
|
401
402
|
> ℹ️ Note: For TypeScript users, `getDecorator` supports generic type parameters.
|
|
402
|
-
> See the [TypeScript documentation](/docs/
|
|
403
|
+
> See the [TypeScript documentation](/docs/Reference/TypeScript.md) for
|
|
403
404
|
> advanced typing examples.
|
|
404
405
|
|
|
405
406
|
#### `setDecorator(name, value)`
|
|
@@ -429,5 +430,5 @@ fastify.addHook('preHandler', async (req, reply) => {
|
|
|
429
430
|
```
|
|
430
431
|
|
|
431
432
|
> ℹ️ Note: For TypeScript users, see the
|
|
432
|
-
> [TypeScript documentation](/docs/
|
|
433
|
+
> [TypeScript documentation](/docs/Reference/TypeScript.md) for advanced
|
|
433
434
|
> typing examples using `setDecorator<T>`.
|
|
@@ -28,8 +28,8 @@ registered within its _grandchild context_.
|
|
|
28
28
|
Given that everything in Fastify is a [plugin](./Plugins.md) except for the
|
|
29
29
|
_root context_, every "context" and "plugin" in this example is a plugin
|
|
30
30
|
that can consist of decorators, hooks, plugins, and routes. As plugins, they
|
|
31
|
-
must still signal completion either by returning a Promise (e.g., using `async`
|
|
32
|
-
or by calling the `done` function if using the callback style.
|
|
31
|
+
must still signal completion either by returning a Promise (e.g., using `async`
|
|
32
|
+
functions) or by calling the `done` function if using the callback style.
|
|
33
33
|
|
|
34
34
|
To put this
|
|
35
35
|
example into concrete terms, consider a basic scenario of a REST API server
|
|
@@ -107,6 +107,10 @@ value is used; otherwise, a new incremental ID is generated. See Fastify Factory
|
|
|
107
107
|
[`requestIdHeader`](./Server.md#factory-request-id-header) and Fastify Factory
|
|
108
108
|
[`genReqId`](./Server.md#genreqid) for customization options.
|
|
109
109
|
|
|
110
|
+
> ⚠ Warning: enabling `requestIdHeader` allows any callers to set `reqId` to a
|
|
111
|
+
> value of their choosing.
|
|
112
|
+
> No validation is performed on `requestIdHeader`.
|
|
113
|
+
|
|
110
114
|
#### Serializers
|
|
111
115
|
The default logger uses standard serializers for objects with `req`, `res`, and
|
|
112
116
|
`err` properties. The `req` object is the Fastify [`Request`](./Request.md)
|
|
@@ -79,8 +79,8 @@ the Fastify instance by a preceding plugin, such as utilizing an existing databa
|
|
|
79
79
|
connection.
|
|
80
80
|
|
|
81
81
|
Keep in mind that the Fastify instance passed to the function is the same as the
|
|
82
|
-
one passed into the plugin, a copy of the external Fastify instance rather than
|
|
83
|
-
reference. Any usage of the instance will behave the same as it would if called
|
|
82
|
+
one passed into the plugin, a copy of the external Fastify instance rather than
|
|
83
|
+
a reference. Any usage of the instance will behave the same as it would if called
|
|
84
84
|
within the plugin's function. For example, if `decorate` is called, the decorated
|
|
85
85
|
variables will be available within the plugin's function unless it was wrapped
|
|
86
86
|
with [`fastify-plugin`](https://github.com/fastify/fastify-plugin).
|
|
@@ -64,8 +64,8 @@ frameworks do this; Fastify does not.
|
|
|
64
64
|
|
|
65
65
|
## Semantic Versioning and Long Term Support
|
|
66
66
|
|
|
67
|
-
A clear [Long Term Support strategy is provided](./LTS.md) to inform developers
|
|
68
|
-
to upgrade.
|
|
67
|
+
A clear [Long Term Support strategy is provided](./LTS.md) to inform developers
|
|
68
|
+
when to upgrade.
|
|
69
69
|
|
|
70
70
|
## Specification adherence
|
|
71
71
|
|
package/docs/Reference/Reply.md
CHANGED
|
@@ -70,8 +70,9 @@ since the request was received by Fastify.
|
|
|
70
70
|
- `.serialize(payload)` - Serializes the specified payload using the default
|
|
71
71
|
JSON serializer or using the custom serializer (if one is set) and returns the
|
|
72
72
|
serialized payload.
|
|
73
|
-
- `.getSerializationFunction(schema | httpStatus, [contentType])` - Returns the
|
|
74
|
-
function for the specified schema or http status, if any of
|
|
73
|
+
- `.getSerializationFunction(schema | httpStatus, [contentType])` - Returns the
|
|
74
|
+
serialization function for the specified schema or http status, if any of
|
|
75
|
+
either are set.
|
|
75
76
|
- `.compileSerializationSchema(schema, [httpStatus], [contentType])` - Compiles
|
|
76
77
|
the specified schema and returns a serialization function using the default
|
|
77
78
|
(or customized) `SerializerCompiler`. The optional `httpStatus` is forwarded
|
package/docs/Reference/Server.md
CHANGED
|
@@ -317,7 +317,7 @@ Pino interface by having the following methods: `info`, `error`, `debug`,
|
|
|
317
317
|
},
|
|
318
318
|
};
|
|
319
319
|
|
|
320
|
-
const fastify = require('fastify')({
|
|
320
|
+
const fastify = require('fastify')({ loggerInstance: customLogger });
|
|
321
321
|
```
|
|
322
322
|
|
|
323
323
|
### `disableRequestLogging`
|
|
@@ -331,6 +331,20 @@ been sent. By setting this option to `true`, these log messages will be
|
|
|
331
331
|
disabled. This allows for more flexible request start and end logging by
|
|
332
332
|
attaching custom `onRequest` and `onResponse` hooks.
|
|
333
333
|
|
|
334
|
+
This option can also be a function that receives the Fastify request object
|
|
335
|
+
and returns a boolean. This allows for conditional request logging based on the
|
|
336
|
+
request properties (e.g., URL, headers, decorations).
|
|
337
|
+
|
|
338
|
+
```js
|
|
339
|
+
const fastify = require('fastify')({
|
|
340
|
+
logger: true,
|
|
341
|
+
disableRequestLogging: (request) => {
|
|
342
|
+
// Disable logging for health check endpoints
|
|
343
|
+
return request.url === '/health' || request.url === '/ready'
|
|
344
|
+
}
|
|
345
|
+
})
|
|
346
|
+
```
|
|
347
|
+
|
|
334
348
|
The other log entries that will be disabled are:
|
|
335
349
|
- an error log written by the default `onResponse` hook on reply callback errors
|
|
336
350
|
- the error and info logs written by the `defaultErrorHandler`
|
|
@@ -413,6 +427,10 @@ const fastify = require('fastify')({
|
|
|
413
427
|
})
|
|
414
428
|
```
|
|
415
429
|
|
|
430
|
+
> ⚠ Warning: enabling this allows any callers to set `reqId` to a
|
|
431
|
+
> value of their choosing.
|
|
432
|
+
> No validation is performed on `requestIdHeader`.
|
|
433
|
+
|
|
416
434
|
### `requestIdLogLabel`
|
|
417
435
|
<a id="factory-request-id-log-label"></a>
|
|
418
436
|
|
|
@@ -565,7 +583,11 @@ const fastify = require('fastify')({
|
|
|
565
583
|
[require('ajv-keywords'), 'instanceof']
|
|
566
584
|
// Usage: [plugin, pluginOptions] - Plugin with options
|
|
567
585
|
// Usage: plugin - Plugin without options
|
|
568
|
-
]
|
|
586
|
+
],
|
|
587
|
+
onCreate: (ajv) => {
|
|
588
|
+
// Modify the ajv instance as you need.
|
|
589
|
+
ajv.addFormat('myFormat', (data) => typeof data === 'string')
|
|
590
|
+
}
|
|
569
591
|
}
|
|
570
592
|
})
|
|
571
593
|
```
|
|
@@ -839,6 +861,12 @@ const fastify = require('fastify')({
|
|
|
839
861
|
})
|
|
840
862
|
```
|
|
841
863
|
|
|
864
|
+
> **Note**
|
|
865
|
+
> The `req` and `res` objects passed to `defaultRoute` are the raw Node.js
|
|
866
|
+
> `IncomingMessage` and `ServerResponse` instances. They do **not** expose the
|
|
867
|
+
> Fastify-specific methods available on `FastifyRequest`/`FastifyReply` (for
|
|
868
|
+
> example, `res.send`).
|
|
869
|
+
|
|
842
870
|
### `ignoreDuplicateSlashes`
|
|
843
871
|
<a id="factory-ignore-duplicate-slashes"></a>
|
|
844
872
|
|
|
@@ -930,6 +958,9 @@ const fastify = require('fastify')({
|
|
|
930
958
|
})
|
|
931
959
|
```
|
|
932
960
|
|
|
961
|
+
As with `defaultRoute`, `req` and `res` are the raw Node.js request/response
|
|
962
|
+
objects and do not provide Fastify's decorated helpers.
|
|
963
|
+
|
|
933
964
|
### `querystringParser`
|
|
934
965
|
<a id="querystringparser"></a>
|
|
935
966
|
|
|
@@ -1789,8 +1820,8 @@ different plugins can set different logger factories.
|
|
|
1789
1820
|
<a id="set-gen-req-id"></a>
|
|
1790
1821
|
|
|
1791
1822
|
`fastify.setGenReqId(function (rawReq))` Synchronous function for setting the request-id
|
|
1792
|
-
for additional Fastify instances. It will receive the _raw_ incoming request as
|
|
1793
|
-
parameter. The provided function should not throw an Error in any case.
|
|
1823
|
+
for additional Fastify instances. It will receive the _raw_ incoming request as
|
|
1824
|
+
a parameter. The provided function should not throw an Error in any case.
|
|
1794
1825
|
|
|
1795
1826
|
Especially in distributed systems, you may want to override the default ID
|
|
1796
1827
|
generation behavior to handle custom ways of generating different IDs in
|
|
@@ -691,7 +691,8 @@ Or even explicit config on tsconfig
|
|
|
691
691
|
|
|
692
692
|
Fastify's `getDecorator<T>` method retrieves decorators with enhanced type safety.
|
|
693
693
|
|
|
694
|
-
The `getDecorator<T>` method supports generic type parameters for enhanced type
|
|
694
|
+
The `getDecorator<T>` method supports generic type parameters for enhanced type
|
|
695
|
+
safety:
|
|
695
696
|
|
|
696
697
|
```typescript
|
|
697
698
|
// Type-safe decorator retrieval
|