fastify 5.9.0 → 5.11.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.
- package/PROJECT_CHARTER.md +1 -1
- package/README.md +7 -10
- package/SPONSORS.md +1 -0
- package/build/build-validation.js +2 -2
- package/docs/Guides/Delay-Accepting-Requests.md +1 -1
- package/docs/Guides/Ecosystem.md +12 -9
- package/docs/Guides/Getting-Started.md +10 -10
- package/docs/Guides/Migration-Guide-V4.md +2 -2
- package/docs/Guides/Migration-Guide-V5.md +1 -1
- package/docs/Guides/Plugins-Guide.md +1 -1
- package/docs/Guides/Prototype-Poisoning.md +3 -3
- package/docs/Guides/Serverless.md +6 -13
- package/docs/Guides/Style-Guide.md +1 -1
- package/docs/Reference/Errors.md +6 -0
- package/docs/Reference/Hooks.md +1 -1
- package/docs/Reference/Logging.md +3 -0
- package/docs/Reference/Reply.md +2 -2
- package/docs/Reference/Request.md +13 -13
- package/docs/Reference/Server.md +117 -17
- package/docs/Reference/Type-Providers.md +24 -4
- package/docs/Reference/TypeScript.md +8 -10
- package/docs/Reference/Warnings.md +5 -0
- package/eslint.config.js +1 -1
- package/fastify.d.ts +60 -13
- package/fastify.js +28 -23
- package/lib/content-type-parser.js +1 -11
- package/lib/content-type.js +70 -19
- package/lib/context.js +0 -3
- package/lib/error-handler.js +7 -26
- package/lib/errors.js +17 -0
- package/lib/four-oh-four.js +8 -10
- package/lib/handle-request.js +37 -8
- package/lib/hooks.js +5 -1
- package/lib/log-controller.js +169 -0
- package/lib/logger-factory.js +25 -4
- package/lib/reply.js +35 -44
- package/lib/req-id-gen-factory.js +4 -1
- package/lib/request.js +3 -3
- package/lib/route.js +28 -36
- package/lib/schemas.js +3 -3
- package/lib/symbols.js +1 -1
- package/lib/validation.js +10 -1
- package/lib/warnings.js +19 -1
- package/package.json +4 -4
- package/test/content-type.test.js +51 -4
- package/test/find-route.test.js +35 -0
- package/test/fix-6411.test.js +65 -0
- package/test/genReqId.test.js +24 -0
- package/test/hooks.test.js +71 -0
- package/test/internals/all.test.js +2 -1
- package/test/internals/errors.test.js +21 -1
- package/test/internals/logger.test.js +322 -0
- package/test/internals/reply.test.js +57 -4
- package/test/internals/request.test.js +10 -7
- package/test/logger/logging.test.js +40 -1
- package/test/reply-error.test.js +35 -0
- package/test/rfc-10008.test.js +147 -0
- package/test/route-shorthand.test.js +14 -4
- package/test/schema-serialization.test.js +33 -0
- package/test/stream.4.test.js +2 -2
- package/test/trust-proxy.test.js +49 -30
- package/test/types/errors.tst.ts +2 -0
- package/test/types/route.tst.ts +3 -3
- package/types/content-type-parser.d.ts +26 -6
- package/types/errors.d.ts +3 -0
- package/types/hooks.d.ts +137 -76
- package/types/instance.d.ts +152 -47
- package/types/logger.d.ts +57 -2
- package/types/plugin.d.ts +7 -3
- package/types/register.d.ts +53 -10
- package/types/reply.d.ts +62 -14
- package/types/route.d.ts +68 -34
- package/types/type-provider.d.ts +29 -8
- package/types/utils.d.ts +2 -2
package/PROJECT_CHARTER.md
CHANGED
|
@@ -50,7 +50,7 @@ experience with the least overhead and a plugin architecture.
|
|
|
50
50
|
|
|
51
51
|
Technical leadership for the projects within the [OpenJS Foundation][openjs
|
|
52
52
|
foundation] is delegated to the projects through their project charters by the
|
|
53
|
-
[OpenJS Foundation Cross-Project Council](https://openjsf.org/
|
|
53
|
+
[OpenJS Foundation Cross-Project Council](https://openjsf.org/governance)
|
|
54
54
|
(CPC). In the case of the Fastify project, it is delegated to the [Fastify
|
|
55
55
|
Collaborators](README.md#team). The OpenJS Foundation's business leadership is
|
|
56
56
|
the Board of Directors (the "Board").
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center"> <a href="https://fastify.dev/">
|
|
2
2
|
<img
|
|
3
|
-
src="https://
|
|
3
|
+
src="https://raw.githubusercontent.com/fastify/graphics/HEAD/fastify-landscape-outlined.svg"
|
|
4
4
|
width="650"
|
|
5
5
|
height="auto"
|
|
6
6
|
/>
|
|
@@ -15,7 +15,7 @@ CI](https://github.com/fastify/fastify/actions/workflows/package-manager-ci.yml/
|
|
|
15
15
|
[](https://github.com/fastify/fastify/actions/workflows/website.yml)
|
|
17
17
|
[](https://github.com/neostandard/neostandard)
|
|
18
|
-
[](https://www.bestpractices.dev/en/projects/7585/passing)
|
|
19
19
|
|
|
20
20
|
</div>
|
|
21
21
|
|
|
@@ -27,7 +27,7 @@ version](https://img.shields.io/npm/v/fastify.svg?style=flat)](https://www.npmjs
|
|
|
27
27
|
downloads](https://img.shields.io/npm/dm/fastify.svg?style=flat)](https://www.npmjs.com/package/fastify)
|
|
28
28
|
[](https://github.com/fastify/fastify/blob/main/SECURITY.md)
|
|
30
|
-
[](https://discord.
|
|
30
|
+
[](https://discord.com/invite/fastify)
|
|
31
31
|
[](https://gitpod.io/#https://github.com/fastify/fastify)
|
|
32
32
|
[](https://github.com/sponsors/fastify#sponsors)
|
|
33
33
|
|
|
@@ -253,8 +253,8 @@ application. You should __always__ benchmark if performance matters to you.
|
|
|
253
253
|
plugins.
|
|
254
254
|
- [Live Examples](https://github.com/fastify/example) - Multirepo with a broad
|
|
255
255
|
set of real working examples.
|
|
256
|
-
- [Discord](https://discord.
|
|
257
|
-
the maintainers.
|
|
256
|
+
- [Discord](https://discord.com/invite/D3FZYPy) - Join our discord server and
|
|
257
|
+
chat with the maintainers.
|
|
258
258
|
|
|
259
259
|
## Support
|
|
260
260
|
Please visit [Fastify help](https://github.com/fastify/help) to view prior
|
|
@@ -312,7 +312,7 @@ listed in alphabetical order.
|
|
|
312
312
|
* [__KaKa Ng__](https://github.com/climba03003),
|
|
313
313
|
<https://www.npmjs.com/~climba03003>
|
|
314
314
|
* [__Luis Orbaiceta__](https://github.com/luisorbaiceta),
|
|
315
|
-
<https://
|
|
315
|
+
<https://www.npmjs.com/~luisorbaiceta>
|
|
316
316
|
* [__Maksim Sinik__](https://github.com/fox1t),
|
|
317
317
|
<https://x.com/maksimsinik>, <https://www.npmjs.com/~fox1t>
|
|
318
318
|
* [__Manuel Spigolon__](https://github.com/eomm),
|
|
@@ -383,7 +383,7 @@ active contributor's group.
|
|
|
383
383
|
## Hosted by
|
|
384
384
|
|
|
385
385
|
[<img
|
|
386
|
-
src="https://
|
|
386
|
+
src="https://raw.githubusercontent.com/openjs-foundation/artwork/main/openjs_foundation/openjs_foundation-logo-horizontal-color.png"
|
|
387
387
|
width="250px;"/>](https://openjsf.org/projects)
|
|
388
388
|
|
|
389
389
|
We are an [At-Large
|
|
@@ -402,9 +402,6 @@ This project is kindly sponsored by:
|
|
|
402
402
|
- [NearForm](https://nearform.com)
|
|
403
403
|
- [Platformatic](https://platformatic.dev)
|
|
404
404
|
|
|
405
|
-
Past Sponsors:
|
|
406
|
-
- [LetzDoIt](https://www.letzdoitapp.com/)
|
|
407
|
-
|
|
408
405
|
This list includes all companies that support one or more team members
|
|
409
406
|
in maintaining this project.
|
|
410
407
|
|
package/SPONSORS.md
CHANGED
|
@@ -32,7 +32,7 @@ const defaultInitOptions = {
|
|
|
32
32
|
bodyLimit: 1024 * 1024, // 1 MiB
|
|
33
33
|
caseSensitive: true,
|
|
34
34
|
allowUnsafeRegex: false,
|
|
35
|
-
disableRequestLogging: false,
|
|
35
|
+
disableRequestLogging: false, // TODO: remove it in v6
|
|
36
36
|
ignoreTrailingSlash: false,
|
|
37
37
|
ignoreDuplicateSlashes: false,
|
|
38
38
|
maxParamLength: 100,
|
|
@@ -40,7 +40,7 @@ const defaultInitOptions = {
|
|
|
40
40
|
onConstructorPoisoning: 'error',
|
|
41
41
|
pluginTimeout: 10000,
|
|
42
42
|
requestIdHeader: false,
|
|
43
|
-
requestIdLogLabel: 'reqId',
|
|
43
|
+
requestIdLogLabel: 'reqId', // TODO: remove it in v6
|
|
44
44
|
http2SessionTimeout: 72000, // 72 seconds
|
|
45
45
|
exposeHeadRoutes: true,
|
|
46
46
|
useSemicolonDelimiter: false,
|
|
@@ -447,7 +447,7 @@ served until we have everything ready. And there's more: we fail **FAST** and
|
|
|
447
447
|
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
|
-
code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503) we're
|
|
450
|
+
code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/503) we're
|
|
451
451
|
signaling to our infrastructure components (namely load balancers) that we're
|
|
452
452
|
still not ready to take incoming requests and they should redirect traffic to
|
|
453
453
|
other instances, if available. Additionally, we are providing a `Retry-After`
|
package/docs/Guides/Ecosystem.md
CHANGED
|
@@ -144,7 +144,7 @@ section.
|
|
|
144
144
|
- [`@fastify/view`](https://github.com/fastify/point-of-view) Templates
|
|
145
145
|
rendering (_ejs, pug, handlebars, marko_) plugin support for Fastify.
|
|
146
146
|
- [`@fastify/vite`](https://github.com/fastify/fastify-vite) Integration with
|
|
147
|
-
[Vite](https://
|
|
147
|
+
[Vite](https://vite.dev/), allows for serving SPA/MPA/SSR Vite applications.
|
|
148
148
|
- [`@fastify/websocket`](https://github.com/fastify/fastify-websocket) WebSocket
|
|
149
149
|
support for Fastify. Built upon [ws](https://github.com/websockets/ws).
|
|
150
150
|
- [`@fastify/zipkin`](https://github.com/fastify/fastify-zipkin) Plugin
|
|
@@ -196,7 +196,7 @@ section.
|
|
|
196
196
|
Run REST APIs and other web applications using your existing Node.js
|
|
197
197
|
application framework (Express, Koa, Hapi and Fastify), on top of AWS Lambda,
|
|
198
198
|
Huawei and many other clouds.
|
|
199
|
-
- [`@hey-api/openapi-ts`](https://heyapi.dev/openapi
|
|
199
|
+
- [`@hey-api/openapi-ts`](https://heyapi.dev/docs/openapi/typescript/plugins/fastify)
|
|
200
200
|
The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more.
|
|
201
201
|
- [`@immobiliarelabs/fastify-metrics`](https://github.com/immobiliare/fastify-metrics)
|
|
202
202
|
Minimalistic and opinionated plugin that collects usage/process metrics and
|
|
@@ -208,8 +208,6 @@ section.
|
|
|
208
208
|
Type-safe dependency injection support for Fastify, powered by [InferDI](https://github.com/inferdi/inferdi).
|
|
209
209
|
- [`@jerome1337/fastify-enforce-routes-pattern`](https://github.com/Jerome1337/fastify-enforce-routes-pattern)
|
|
210
210
|
A Fastify plugin that enforces naming pattern for routes path.
|
|
211
|
-
- [`@joggr/fastify-prisma`](https://github.com/joggrdocs/fastify-prisma)
|
|
212
|
-
A plugin for accessing an instantiated PrismaClient on your server.
|
|
213
211
|
- [`@matths/fastify-svelte-view`](https://github.com/matths/fastify-svelte-view)
|
|
214
212
|
A Fastify plugin for rendering Svelte components with support for SSR
|
|
215
213
|
(Server-Side Rendering), CSR (Client-Side Rendering), and SSR with hydration.
|
|
@@ -232,6 +230,9 @@ section.
|
|
|
232
230
|
Plugin to generate routes automatically with valid json content
|
|
233
231
|
- [`@scalar/fastify-api-reference`](https://github.com/scalar/scalar/tree/main/integrations/fastify)
|
|
234
232
|
Beautiful OpenAPI/Swagger API references for Fastify
|
|
233
|
+
- [`@stitchapi/fastify`](https://github.com/rejifald/StitchAPI/tree/main/packages/fastify)
|
|
234
|
+
Decorate the app/request with a StitchAPI seam — request-scoped principal, SSE
|
|
235
|
+
streaming, error mapping, and a Pino-logger bridge.
|
|
235
236
|
- [`@thecodepace/fastify-http-query`](https://github.com/TheCodePace/fastify-http-query)
|
|
236
237
|
Fastify plugin enabling the HTTP `QUERY` method (a safe, idempotent, cacheable
|
|
237
238
|
method with a body).
|
|
@@ -239,6 +240,8 @@ section.
|
|
|
239
240
|
SeaweedFS for Fastify
|
|
240
241
|
- [`@yeliex/fastify-problem-details`](https://github.com/yeliex/fastify-problem-details)
|
|
241
242
|
RFC 9457 Problem Details implementation for Fastify, with typed HTTP errors.
|
|
243
|
+
- [`@zrosenbauer/fastify-prisma`](https://github.com/zrosenbauer/fastify-prisma)
|
|
244
|
+
A plugin for accessing an instantiated PrismaClient on your server.
|
|
242
245
|
- [`apitally`](https://github.com/apitally/apitally-js) Fastify plugin to
|
|
243
246
|
integrate with [Apitally](https://apitally.io/fastify), an API analytics,
|
|
244
247
|
logging and monitoring tool.
|
|
@@ -289,8 +292,8 @@ section.
|
|
|
289
292
|
validator, keeping Fastify's default error shape.
|
|
290
293
|
- [`fastify-auth0-verify`](https://github.com/nearform/fastify-auth0-verify):
|
|
291
294
|
Auth0 verification plugin for Fastify, internally uses
|
|
292
|
-
[fastify-jwt](https://
|
|
293
|
-
[jsonwebtoken](https://
|
|
295
|
+
[fastify-jwt](https://www.npmjs.com/package/fastify-jwt) and
|
|
296
|
+
[jsonwebtoken](https://www.npmjs.com/package/jsonwebtoken).
|
|
294
297
|
- [`fastify-autoroutes`](https://github.com/GiovanniCardamone/fastify-autoroutes)
|
|
295
298
|
Plugin to scan and load routes based on filesystem path from a custom
|
|
296
299
|
directory.
|
|
@@ -390,7 +393,7 @@ section.
|
|
|
390
393
|
- [`fastify-formidable`](https://github.com/climba03003/fastify-formidable)
|
|
391
394
|
Handy plugin to provide multipart support and fastify-swagger integration.
|
|
392
395
|
- [`fastify-gcloud-trace`](https://github.com/mkinoshi/fastify-gcloud-trace)
|
|
393
|
-
[Google Cloud Trace API](https://cloud.google.com/trace/docs/reference)
|
|
396
|
+
[Google Cloud Trace API](https://docs.cloud.google.com/trace/docs/reference)
|
|
394
397
|
Connector for Fastify.
|
|
395
398
|
- [`fastify-get-head`](https://github.com/MetCoder95/fastify-get-head) Small
|
|
396
399
|
plugin to set a new HEAD route handler for each GET route previously
|
|
@@ -561,7 +564,7 @@ middlewares into Fastify plugins
|
|
|
561
564
|
to handle i18n using
|
|
562
565
|
[node-polyglot](https://www.npmjs.com/package/node-polyglot).
|
|
563
566
|
- [`fastify-postgraphile`](https://github.com/alemagio/fastify-postgraphile)
|
|
564
|
-
Plugin to integrate [PostGraphile](https://
|
|
567
|
+
Plugin to integrate [PostGraphile](https://postgraphile.org/postgraphile/4/) in
|
|
565
568
|
a Fastify project.
|
|
566
569
|
- [`fastify-postgres-dot-js`](https://github.com/kylerush/fastify-postgresjs) Fastify
|
|
567
570
|
PostgreSQL connection plugin that uses [Postgres.js](https://github.com/porsager/postgres).
|
|
@@ -679,7 +682,7 @@ middlewares into Fastify plugins
|
|
|
679
682
|
multiple subdomains to the same IP address, while running different servers on
|
|
680
683
|
the same machine).
|
|
681
684
|
- [`fastify-vue-plugin`](https://github.com/TheNoim/fastify-vue)
|
|
682
|
-
[Nuxt.js](https://
|
|
685
|
+
[Nuxt.js](https://nuxt.com) plugin for Fastify. Control the routes nuxt
|
|
683
686
|
should use.
|
|
684
687
|
- [`fastify-wamp-router`](https://github.com/lependu/fastify-wamp-router) Web
|
|
685
688
|
Application Messaging Protocol router for Fastify.
|
|
@@ -146,7 +146,7 @@ declaration](../Reference/Routes.md) docs).
|
|
|
146
146
|
```js
|
|
147
147
|
// ESM
|
|
148
148
|
import Fastify from 'fastify'
|
|
149
|
-
import
|
|
149
|
+
import routes from './our-first-routes.js'
|
|
150
150
|
/**
|
|
151
151
|
* @type {import('fastify').FastifyInstance} Instance of Fastify
|
|
152
152
|
*/
|
|
@@ -154,7 +154,7 @@ const fastify = Fastify({
|
|
|
154
154
|
logger: true
|
|
155
155
|
})
|
|
156
156
|
|
|
157
|
-
fastify.register(
|
|
157
|
+
fastify.register(routes)
|
|
158
158
|
|
|
159
159
|
fastify.listen({ port: 3000 }, function (err, address) {
|
|
160
160
|
if (err) {
|
|
@@ -174,7 +174,7 @@ const fastify = require('fastify')({
|
|
|
174
174
|
logger: true
|
|
175
175
|
})
|
|
176
176
|
|
|
177
|
-
fastify.register(require('./our-first-
|
|
177
|
+
fastify.register(require('./our-first-routes'))
|
|
178
178
|
|
|
179
179
|
fastify.listen({ port: 3000 }, function (err, address) {
|
|
180
180
|
if (err) {
|
|
@@ -187,7 +187,7 @@ fastify.listen({ port: 3000 }, function (err, address) {
|
|
|
187
187
|
|
|
188
188
|
|
|
189
189
|
```js
|
|
190
|
-
// our-first-
|
|
190
|
+
// our-first-routes.js
|
|
191
191
|
|
|
192
192
|
/**
|
|
193
193
|
* Encapsulates the routes
|
|
@@ -236,7 +236,7 @@ npm i fastify-plugin @fastify/mongodb
|
|
|
236
236
|
// ESM
|
|
237
237
|
import Fastify from 'fastify'
|
|
238
238
|
import dbConnector from './our-db-connector.js'
|
|
239
|
-
import
|
|
239
|
+
import routes from './our-first-routes.js'
|
|
240
240
|
|
|
241
241
|
/**
|
|
242
242
|
* @type {import('fastify').FastifyInstance} Instance of Fastify
|
|
@@ -245,7 +245,7 @@ const fastify = Fastify({
|
|
|
245
245
|
logger: true
|
|
246
246
|
})
|
|
247
247
|
fastify.register(dbConnector)
|
|
248
|
-
fastify.register(
|
|
248
|
+
fastify.register(routes)
|
|
249
249
|
|
|
250
250
|
fastify.listen({ port: 3000 }, function (err, address) {
|
|
251
251
|
if (err) {
|
|
@@ -266,7 +266,7 @@ const fastify = require('fastify')({
|
|
|
266
266
|
})
|
|
267
267
|
|
|
268
268
|
fastify.register(require('./our-db-connector'))
|
|
269
|
-
fastify.register(require('./our-first-
|
|
269
|
+
fastify.register(require('./our-first-routes'))
|
|
270
270
|
|
|
271
271
|
fastify.listen({ port: 3000 }, function (err, address) {
|
|
272
272
|
if (err) {
|
|
@@ -325,7 +325,7 @@ module.exports = fastifyPlugin(dbConnector)
|
|
|
325
325
|
|
|
326
326
|
```
|
|
327
327
|
|
|
328
|
-
**our-first-
|
|
328
|
+
**our-first-routes.js**
|
|
329
329
|
```js
|
|
330
330
|
/**
|
|
331
331
|
* A plugin that provide encapsulated routes
|
|
@@ -605,10 +605,10 @@ npm start
|
|
|
605
605
|
|
|
606
606
|
- Slides
|
|
607
607
|
- [Take your HTTP server to ludicrous
|
|
608
|
-
speed](https://mcollina.github.io/take-your-http-server-to-ludicrous-speed)
|
|
608
|
+
speed](https://mcollina.github.io/take-your-http-server-to-ludicrous-speed/)
|
|
609
609
|
by [@mcollina](https://github.com/mcollina)
|
|
610
610
|
- [What if I told you that HTTP can be
|
|
611
|
-
fast](https://delvedor.
|
|
611
|
+
fast](https://delvedor.dev/What-if-I-told-you-that-HTTP-can-be-fast/)
|
|
612
612
|
by [@delvedor](https://github.com/delvedor)
|
|
613
613
|
|
|
614
614
|
- Videos
|
|
@@ -10,7 +10,7 @@ work after upgrading.
|
|
|
10
10
|
### Fastify v4 Codemods
|
|
11
11
|
|
|
12
12
|
To help with the upgrade, we’ve worked with the team at
|
|
13
|
-
[Codemod](https://github.com/codemod
|
|
13
|
+
[Codemod](https://github.com/codemod/codemod) to
|
|
14
14
|
publish codemods that will automatically update your code to many of
|
|
15
15
|
the new APIs and patterns in Fastify v4.
|
|
16
16
|
|
|
@@ -264,4 +264,4 @@ Into:
|
|
|
264
264
|
Fastify now supports the [HTTP Trailer] response headers.
|
|
265
265
|
|
|
266
266
|
|
|
267
|
-
[HTTP Trailer]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer
|
|
267
|
+
[HTTP Trailer]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Trailer
|
|
@@ -105,7 +105,7 @@ const fastify = require('fastify')({
|
|
|
105
105
|
Starting with v5, Fastify instances will no longer default to supporting the use
|
|
106
106
|
of semicolon delimiters in the query string as they did in v4.
|
|
107
107
|
This is due to it being non-standard
|
|
108
|
-
behavior and not adhering to [RFC 3986](https://
|
|
108
|
+
behavior and not adhering to [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986#section-3.4).
|
|
109
109
|
|
|
110
110
|
If you still wish to use semicolons as delimiters, you can do so by
|
|
111
111
|
setting `useSemicolonDelimiter: true` in the server configuration.
|
|
@@ -507,7 +507,7 @@ section of our documentation!
|
|
|
507
507
|
|
|
508
508
|
If you want to see some real-world examples, check out:
|
|
509
509
|
- [`@fastify/view`](https://github.com/fastify/point-of-view) Templates
|
|
510
|
-
rendering (*ejs, pug, handlebars
|
|
510
|
+
rendering (*ejs, pug, handlebars*) plugin support for Fastify.
|
|
511
511
|
- [`@fastify/mongodb`](https://github.com/fastify/fastify-mongodb) Fastify
|
|
512
512
|
MongoDB connection plugin, with this you can share the same MongoDB connection
|
|
513
513
|
pool in every part of your server.
|
|
@@ -232,7 +232,7 @@ itself), it is much harder getting it fixed.
|
|
|
232
232
|
|
|
233
233
|
The first question people ask once a security issue is found is if there is
|
|
234
234
|
going to be a CVE published. A CVE — Common Vulnerabilities and Exposures — is a
|
|
235
|
-
[database](https://cve.
|
|
235
|
+
[database](https://www.cve.org/) of known security issues. It is a critical
|
|
236
236
|
component of web security. The benefit of publishing a CVE is that it
|
|
237
237
|
immediately triggers alarms and informs and often breaks automated builds until
|
|
238
238
|
the issue is resolved.
|
|
@@ -376,8 +376,8 @@ source maintainers.
|
|
|
376
376
|
Because this work is important, I decided to try and make it not just
|
|
377
377
|
financially sustainable but to grow and expand it. There is so much to improve.
|
|
378
378
|
This is exactly what motivates me to implement the new [commercial licensing
|
|
379
|
-
plan](https://web.archive.org/web/20190201220503/https://hueniverse.com/on-hapi-licensing-a-preview-f982662ee898)
|
|
379
|
+
plan](https://web.archive.org/web/20190201220503/https://hueniverse.com/on-hapi-licensing-a-preview-f982662ee898?gi=b54e9a75bac6)
|
|
380
380
|
coming in March. You can read more about it
|
|
381
|
-
[here](https://web.archive.org/web/20190201220503/https://hueniverse.com/on-hapi-licensing-a-preview-f982662ee898).
|
|
381
|
+
[here](https://web.archive.org/web/20190201220503/https://hueniverse.com/on-hapi-licensing-a-preview-f982662ee898?gi=b54e9a75bac6).
|
|
382
382
|
|
|
383
383
|
|
|
@@ -109,13 +109,6 @@ signature to be used as a lambda `handler` function. This way all the incoming
|
|
|
109
109
|
events (API Gateway requests) are passed to the `proxy` function of
|
|
110
110
|
[@fastify/aws-lambda](https://github.com/fastify/aws-lambda-fastify).
|
|
111
111
|
|
|
112
|
-
#### Example
|
|
113
|
-
|
|
114
|
-
An example deployable with
|
|
115
|
-
[claudia.js](https://claudiajs.com/tutorials/serverless-express.html) can be
|
|
116
|
-
found
|
|
117
|
-
[here](https://github.com/claudiajs/example-projects/tree/master/fastify-app-lambda).
|
|
118
|
-
|
|
119
112
|
### Considerations
|
|
120
113
|
|
|
121
114
|
- API Gateway does not support streams yet, so you are not able to handle
|
|
@@ -126,7 +119,7 @@ found
|
|
|
126
119
|
#### Beyond API Gateway
|
|
127
120
|
|
|
128
121
|
If you need to integrate with more AWS services, take a look at
|
|
129
|
-
[@h4ad/serverless-adapter](https://viniciusl.com.br/
|
|
122
|
+
[@h4ad/serverless-adapter](https://serverless-adapter.viniciusl.com.br/docs/main/frameworks/fastify)
|
|
130
123
|
on Fastify to find out how to integrate.
|
|
131
124
|
|
|
132
125
|
## Genezio
|
|
@@ -134,7 +127,7 @@ on Fastify to find out how to integrate.
|
|
|
134
127
|
[Genezio](https://genezio.com/) is a platform designed to simplify the deployment
|
|
135
128
|
of serverless applications to the cloud.
|
|
136
129
|
|
|
137
|
-
[Genezio has a dedicated guide for deploying a Fastify application.](https://
|
|
130
|
+
[Genezio has a dedicated guide for deploying a Fastify application.](https://deployapps.dev/docs/frameworks/fastify/)
|
|
138
131
|
|
|
139
132
|
## Google Cloud Functions
|
|
140
133
|
|
|
@@ -265,7 +258,7 @@ curl -X POST https://$GOOGLE_REGION-$GOOGLE_PROJECT.cloudfunctions.net/me \
|
|
|
265
258
|
|
|
266
259
|
### References
|
|
267
260
|
- [Google Cloud Functions - Node.js Quickstart
|
|
268
|
-
](https://cloud.google.com/
|
|
261
|
+
](https://docs.cloud.google.com/run/docs/quickstarts/functions/deploy-functions-gcloud)
|
|
269
262
|
|
|
270
263
|
## Google Firebase Functions
|
|
271
264
|
|
|
@@ -403,7 +396,7 @@ the way you would write your Fastify app normally.
|
|
|
403
396
|
|
|
404
397
|
*Follow the steps below to deploy to Google Cloud Run if you are already
|
|
405
398
|
familiar with gcloud or just follow their
|
|
406
|
-
[quickstart](https://cloud.google.com/run/docs/quickstarts
|
|
399
|
+
[quickstart](https://docs.cloud.google.com/run/docs/quickstarts)*.
|
|
407
400
|
|
|
408
401
|
### Adjust Fastify server
|
|
409
402
|
|
|
@@ -590,7 +583,7 @@ Then it should work fine.
|
|
|
590
583
|
|
|
591
584
|
[Vercel](https://vercel.com) fully supports deploying Fastify applications.
|
|
592
585
|
Additionally, with Vercel's
|
|
593
|
-
[Fluid compute](https://vercel.com/docs/
|
|
586
|
+
[Fluid compute](https://vercel.com/docs/fluid-compute), you can combine
|
|
594
587
|
server-like concurrency with the autoscaling properties of traditional
|
|
595
588
|
serverless functions.
|
|
596
589
|
|
|
@@ -598,7 +591,7 @@ Get started with the
|
|
|
598
591
|
[Fastify template on Vercel](
|
|
599
592
|
https://vercel.com/templates/backend/fastify-on-vercel).
|
|
600
593
|
|
|
601
|
-
[Fluid compute](https://vercel.com/docs/
|
|
594
|
+
[Fluid compute](https://vercel.com/docs/fluid-compute) currently
|
|
602
595
|
requires an explicit opt-in. Learn more about enabling Fluid compute
|
|
603
596
|
[here](
|
|
604
597
|
https://vercel.com/docs/fluid-compute#enabling-fluid-compute).
|
|
@@ -13,7 +13,7 @@ This guide is for anyone who loves to build with Fastify or wants to contribute
|
|
|
13
13
|
to our documentation. You do not need to be an expert in writing technical
|
|
14
14
|
documentation. This guide is here to help you.
|
|
15
15
|
|
|
16
|
-
Visit the [contribute](https://fastify.dev/contribute) page on our website or
|
|
16
|
+
Visit the [contribute](https://fastify.dev/contribute/) page on our website or
|
|
17
17
|
read the
|
|
18
18
|
[CONTRIBUTING.md](https://github.com/fastify/fastify/blob/main/CONTRIBUTING.md)
|
|
19
19
|
file on GitHub to join our Open Source folks.
|
package/docs/Reference/Errors.md
CHANGED
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
- [FST_ERR_LOG_INVALID_LOGGER_INSTANCE](#fst_err_log_invalid_logger_instance)
|
|
50
50
|
- [FST_ERR_LOG_INVALID_LOGGER_CONFIG](#fst_err_log_invalid_logger_config)
|
|
51
51
|
- [FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED](#fst_err_log_logger_and_logger_instance_provided)
|
|
52
|
+
- [FST_ERR_LOG_INVALID_LOG_CONTROLLER](#fst_err_log_invalid_log_controller)
|
|
52
53
|
- [FST_ERR_REP_INVALID_PAYLOAD_TYPE](#fst_err_rep_invalid_payload_type)
|
|
53
54
|
- [FST_ERR_REP_RESPONSE_BODY_CONSUMED](#fst_err_rep_response_body_consumed)
|
|
54
55
|
- [FST_ERR_REP_READABLE_STREAM_LOCKED](#fst_err_rep_readable_stream_locked)
|
|
@@ -90,6 +91,8 @@
|
|
|
90
91
|
|
|
91
92
|
- [FST_ERR_ROUTE_HANDLER_TIMEOUT_OPTION_NOT_INT](#fst_err_route_handler_timeout_option_not_int)
|
|
92
93
|
- [FST_ERR_ROUTE_REWRITE_NOT_STR](#fst_err_route_rewrite_not_str)
|
|
94
|
+
- [FST_ERR_ROUTE_MISSING_CONTENT_TYPE](#fst_err_route_missing_content_type)
|
|
95
|
+
- [FST_ERR_ROUTE_MISSING_CONTENT](#fst_err_route_missing_content)
|
|
93
96
|
- [FST_ERR_REOPENED_CLOSE_SERVER](#fst_err_reopened_close_server)
|
|
94
97
|
- [FST_ERR_REOPENED_SERVER](#fst_err_reopened_server)
|
|
95
98
|
- [FST_ERR_PLUGIN_VERSION_MISMATCH](#fst_err_plugin_version_mismatch)
|
|
@@ -327,6 +330,7 @@ Below is a table with all the error codes used by Fastify.
|
|
|
327
330
|
| <a id="fst_err_log_invalid_logger_instance">FST_ERR_LOG_INVALID_LOGGER_INSTANCE</a> | The `loggerInstance` only accepts a logger instance, not a configuration object. | To pass a configuration object, use `'logger'` instead. | [#5020](https://github.com/fastify/fastify/pull/5020) |
|
|
328
331
|
| <a id="fst_err_log_invalid_logger_config">FST_ERR_LOG_INVALID_LOGGER_CONFIG</a> | The logger option only accepts a configuration object, not a logger instance. | To pass an instance, use `'loggerInstance'` instead. | [#5020](https://github.com/fastify/fastify/pull/5020) |
|
|
329
332
|
| <a id="fst_err_log_logger_and_logger_instance_provided">FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED</a> | You cannot provide both `'logger'` and `'loggerInstance'`. | Please provide only one option. | [#5020](https://github.com/fastify/fastify/pull/5020) |
|
|
333
|
+
| <a id="fst_err_log_invalid_log_controller">FST_ERR_LOG_INVALID_LOG_CONTROLLER</a> | The `logController` option must be an instance of `LogController`. | Extend the `LogController` class and pass an instance. | - |
|
|
330
334
|
| <a id="fst_err_rep_invalid_payload_type">FST_ERR_REP_INVALID_PAYLOAD_TYPE</a> | Reply payload can be either a `string` or a `Buffer`. | Use a `string` or a `Buffer` for the payload. | [#1168](https://github.com/fastify/fastify/pull/1168) |
|
|
331
335
|
| <a id="fst_err_rep_response_body_consumed">FST_ERR_REP_RESPONSE_BODY_CONSUMED</a> | Using `Response` as reply payload, but the body is being consumed. | Make sure you don't consume the `Response.body` | [#5286](https://github.com/fastify/fastify/pull/5286) |
|
|
332
336
|
| <a id="fst_err_rep_readable_stream_locked">FST_ERR_REP_READABLE_STREAM_LOCKED</a> | Using `ReadableStream` as reply payload, but locked with another reader. | Make sure you don't call the `Readable.getReader` before sending or release lock with `reader.releaseLock()` before sending. | [#5920](https://github.com/fastify/fastify/pull/5920) |
|
|
@@ -367,6 +371,8 @@ Below is a table with all the error codes used by Fastify.
|
|
|
367
371
|
| <a id="fst_err_handler_timeout">FST_ERR_HANDLER_TIMEOUT</a> | Request timed out. | Increase the `handlerTimeout` option or optimize the handler. | - |
|
|
368
372
|
| <a id="fst_err_route_handler_timeout_option_not_int">FST_ERR_ROUTE_HANDLER_TIMEOUT_OPTION_NOT_INT</a> | `handlerTimeout` option must be a positive integer. | Use a positive integer for the `handlerTimeout` option. | - |
|
|
369
373
|
| <a id="fst_err_route_rewrite_not_str">FST_ERR_ROUTE_REWRITE_NOT_STR</a> | `rewriteUrl` needs to be of type `string`. | Use a string for the `rewriteUrl`. | [#4554](https://github.com/fastify/fastify/pull/4554) |
|
|
374
|
+
| <a id="fst_err_route_missing_content_type">FST_ERR_ROUTE_MISSING_CONTENT_TYPE</a> | `Content-Type` header is required for the request. | Send request with `Content-Type` header. | [#6832](https://github.com/fastify/fastify/pull/6832) |
|
|
375
|
+
| <a id="fst_err_route_missing_content">FST_ERR_ROUTE_MISSING_CONTENT</a> | Body is required for the request. | Send request with payload. | [#6832](https://github.com/fastify/fastify/pull/6832) |
|
|
370
376
|
| <a id="fst_err_reopened_close_server">FST_ERR_REOPENED_CLOSE_SERVER</a> | Fastify has already been closed and cannot be reopened. | - | [#2415](https://github.com/fastify/fastify/pull/2415) |
|
|
371
377
|
| <a id="fst_err_reopened_server">FST_ERR_REOPENED_SERVER</a> | Fastify is already listening. | - | [#2415](https://github.com/fastify/fastify/pull/2415) |
|
|
372
378
|
| <a id="fst_err_plugin_version_mismatch">FST_ERR_PLUGIN_VERSION_MISMATCH</a> | Installed Fastify plugin mismatched expected version. | Use a compatible version of the plugin. | [#2549](https://github.com/fastify/fastify/pull/2549) |
|
package/docs/Reference/Hooks.md
CHANGED
|
@@ -51,7 +51,7 @@ It is easy to understand where each hook is executed by looking at the
|
|
|
51
51
|
Hooks are affected by Fastify's encapsulation, and can thus be applied to
|
|
52
52
|
selected routes. See the [Scopes](#scope) section for more information.
|
|
53
53
|
|
|
54
|
-
There are
|
|
54
|
+
There are ten different hooks that you can use in Request/Reply *(in order of
|
|
55
55
|
execution)*:
|
|
56
56
|
|
|
57
57
|
### onRequest
|
|
@@ -13,6 +13,9 @@ As Fastify is focused on performance, it uses
|
|
|
13
13
|
[pino](https://github.com/pinojs/pino) as its logger, with the default log
|
|
14
14
|
level set to `'info'` when enabled.
|
|
15
15
|
|
|
16
|
+
The log level can be set per-route. See [the routes
|
|
17
|
+
documentation](./Routes.md#custom-log-level).
|
|
18
|
+
|
|
16
19
|
#### Basic Logging Setup
|
|
17
20
|
The following enables the production JSON logger:
|
|
18
21
|
|
package/docs/Reference/Reply.md
CHANGED
|
@@ -271,7 +271,7 @@ as soon as possible.
|
|
|
271
271
|
> in the error, you can turn on `debug` level logging.
|
|
272
272
|
|
|
273
273
|
```js
|
|
274
|
-
reply.trailer('server-timing', function() {
|
|
274
|
+
reply.trailer('server-timing', async function () {
|
|
275
275
|
return 'db;dur=53, app;dur=47.2'
|
|
276
276
|
})
|
|
277
277
|
|
|
@@ -304,7 +304,7 @@ Returns a boolean indicating if the specified trailer has been set.
|
|
|
304
304
|
|
|
305
305
|
Remove the value of a previously set trailer.
|
|
306
306
|
```js
|
|
307
|
-
reply.trailer('server-timing', function() {
|
|
307
|
+
reply.trailer('server-timing', async function () {
|
|
308
308
|
return 'db;dur=53, app;dur=47.2'
|
|
309
309
|
})
|
|
310
310
|
reply.removeTrailer('server-timing')
|
|
@@ -34,14 +34,14 @@ Request is a core Fastify object containing the following fields:
|
|
|
34
34
|
value comes from `socket.encrypted` (or `X-Forwarded-Proto` when
|
|
35
35
|
[`trustProxy`](./Server.md#factory-trust-proxy) is enabled).
|
|
36
36
|
|
|
37
|
-
> ⚠️ Security:
|
|
38
|
-
> `request.ip`, `request.ips`, `request.host`, `request.hostname`,
|
|
39
|
-
> `request.port`, and `request.protocol` come from request metadata
|
|
40
|
-
> (socket and/or forwarding headers) and should be treated as untrusted input.
|
|
41
|
-
> Fastify does not perform security validation for business logic.
|
|
42
|
-
> If these values are used in security-sensitive decisions, they must
|
|
43
|
-
> be validated explicitly (for example: trusted proxy configuration,
|
|
44
|
-
> allow-lists, strict parsing, and normalization).
|
|
37
|
+
> ⚠️ Security:
|
|
38
|
+
> `request.ip`, `request.ips`, `request.host`, `request.hostname`,
|
|
39
|
+
> `request.port`, and `request.protocol` come from request metadata
|
|
40
|
+
> (socket and/or forwarding headers) and should be treated as untrusted input.
|
|
41
|
+
> Fastify does not perform security validation for business logic.
|
|
42
|
+
> If these values are used in security-sensitive decisions, they must
|
|
43
|
+
> be validated explicitly (for example: trusted proxy configuration,
|
|
44
|
+
> allow-lists, strict parsing, and normalization).
|
|
45
45
|
|
|
46
46
|
- `method` - The method of the incoming request.
|
|
47
47
|
- `url` - The URL of the incoming request.
|
|
@@ -87,9 +87,9 @@ Request is a core Fastify object containing the following fields:
|
|
|
87
87
|
default (or customized) `ValidationCompiler`. The optional `httpPart` is
|
|
88
88
|
forwarded to the `ValidationCompiler` if provided, defaults to `null`.
|
|
89
89
|
- [.validateInput(data, schema | httpPart, [httpPart])](#validate) -
|
|
90
|
-
Validates the input using the specified schema and returns
|
|
91
|
-
|
|
92
|
-
that HTTP
|
|
90
|
+
Validates the input using the specified schema or HTTP part and returns
|
|
91
|
+
`true` if the input is valid, `false` otherwise. If `httpPart` is provided,
|
|
92
|
+
the function uses the validator for that HTTP part. Defaults to `null`.
|
|
93
93
|
|
|
94
94
|
### Headers
|
|
95
95
|
|
|
@@ -132,14 +132,14 @@ fastify.post('/:params', options, function (request, reply) {
|
|
|
132
132
|
console.log(request.url)
|
|
133
133
|
console.log(request.routeOptions.method)
|
|
134
134
|
console.log(request.routeOptions.bodyLimit)
|
|
135
|
-
console.log(request.routeOptions.
|
|
135
|
+
console.log(request.routeOptions.handlerTimeout)
|
|
136
136
|
console.log(request.routeOptions.url)
|
|
137
137
|
console.log(request.routeOptions.attachValidation)
|
|
138
138
|
console.log(request.routeOptions.logLevel)
|
|
139
139
|
console.log(request.routeOptions.version)
|
|
140
140
|
console.log(request.routeOptions.exposeHeadRoute)
|
|
141
141
|
console.log(request.routeOptions.prefixTrailingSlash)
|
|
142
|
-
console.log(request.routeOptions.
|
|
142
|
+
console.log(request.routeOptions.config)
|
|
143
143
|
request.log.info('some info')
|
|
144
144
|
})
|
|
145
145
|
```
|