fastify 5.3.3 â 5.5.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/.vscode/settings.json +15 -15
- package/LICENSE +1 -1
- package/README.md +2 -0
- package/SECURITY.md +158 -2
- package/build/build-validation.js +20 -1
- package/docs/Guides/Delay-Accepting-Requests.md +8 -5
- package/docs/Guides/Ecosystem.md +20 -5
- package/docs/Guides/Migration-Guide-V5.md +6 -10
- package/docs/Guides/Recommendations.md +1 -1
- package/docs/Reference/ContentTypeParser.md +1 -1
- package/docs/Reference/Errors.md +5 -3
- package/docs/Reference/Hooks.md +16 -20
- package/docs/Reference/Lifecycle.md +2 -2
- package/docs/Reference/Logging.md +3 -3
- package/docs/Reference/Middleware.md +1 -1
- package/docs/Reference/Reply.md +8 -8
- package/docs/Reference/Request.md +2 -2
- package/docs/Reference/Routes.md +7 -6
- package/docs/Reference/Server.md +341 -200
- package/docs/Reference/TypeScript.md +1 -3
- package/docs/Reference/Validation-and-Serialization.md +56 -4
- package/docs/Reference/Warnings.md +2 -1
- package/fastify.d.ts +4 -3
- package/fastify.js +47 -34
- package/lib/configValidator.js +196 -28
- package/lib/contentTypeParser.js +41 -48
- package/lib/error-handler.js +3 -3
- package/lib/errors.js +11 -0
- package/lib/handleRequest.js +13 -17
- package/lib/pluginOverride.js +3 -1
- package/lib/promise.js +23 -0
- package/lib/reply.js +24 -30
- package/lib/request.js +3 -10
- package/lib/route.js +37 -3
- package/lib/server.js +36 -35
- package/lib/symbols.js +1 -0
- package/lib/warnings.js +19 -1
- package/package.json +14 -10
- package/test/404s.test.js +226 -325
- package/test/allow-unsafe-regex.test.js +19 -48
- package/test/als.test.js +28 -40
- package/test/async-await.test.js +84 -128
- package/test/async_hooks.test.js +18 -37
- package/test/body-limit.test.js +90 -63
- package/test/buffer.test.js +22 -0
- package/test/build-certificate.js +1 -1
- package/test/case-insensitive.test.js +44 -65
- package/test/check.test.js +17 -21
- package/test/close-pipelining.test.js +24 -15
- package/test/constrained-routes.test.js +231 -0
- package/test/custom-http-server.test.js +7 -15
- package/test/custom-parser-async.test.js +17 -22
- package/test/custom-parser.0.test.js +267 -348
- package/test/custom-parser.1.test.js +141 -191
- package/test/custom-parser.2.test.js +34 -44
- package/test/custom-parser.3.test.js +56 -104
- package/test/custom-parser.4.test.js +106 -144
- package/test/custom-parser.5.test.js +56 -75
- package/test/custom-querystring-parser.test.js +51 -77
- package/test/decorator-namespace.test._js_ +3 -4
- package/test/decorator.test.js +76 -259
- package/test/delete.test.js +101 -110
- package/test/diagnostics-channel/404.test.js +7 -15
- package/test/diagnostics-channel/async-delay-request.test.js +7 -16
- package/test/diagnostics-channel/async-request.test.js +8 -16
- package/test/diagnostics-channel/error-request.test.js +7 -15
- package/test/diagnostics-channel/sync-delay-request.test.js +7 -16
- package/test/diagnostics-channel/sync-request-reply.test.js +9 -16
- package/test/diagnostics-channel/sync-request.test.js +9 -16
- package/test/fastify-instance.test.js +1 -1
- package/test/header-overflow.test.js +18 -29
- package/test/helper.js +139 -135
- package/test/hooks-async.test.js +259 -235
- package/test/hooks.test.js +951 -996
- package/test/http-methods/copy.test.js +14 -19
- package/test/http-methods/get.test.js +131 -143
- package/test/http-methods/head.test.js +53 -84
- package/test/http-methods/lock.test.js +31 -31
- package/test/http-methods/mkcalendar.test.js +45 -72
- package/test/http-methods/mkcol.test.js +5 -9
- package/test/http-methods/move.test.js +6 -10
- package/test/http-methods/propfind.test.js +34 -44
- package/test/http-methods/proppatch.test.js +23 -29
- package/test/http-methods/report.test.js +44 -69
- package/test/http-methods/search.test.js +67 -82
- package/test/http-methods/unlock.test.js +5 -9
- package/test/http2/closing.test.js +38 -20
- package/test/http2/secure-with-fallback.test.js +31 -28
- package/test/https/custom-https-server.test.js +9 -13
- package/test/https/https.test.js +56 -53
- package/test/input-validation.js +139 -150
- package/test/internals/errors.test.js +50 -1
- package/test/internals/handle-request.test.js +72 -65
- package/test/internals/promise.test.js +63 -0
- package/test/internals/reply.test.js +277 -496
- package/test/issue-4959.test.js +12 -3
- package/test/listen.4.test.js +31 -43
- package/test/nullable-validation.test.js +33 -46
- package/test/output-validation.test.js +24 -26
- package/test/plugin.1.test.js +40 -68
- package/test/plugin.2.test.js +108 -120
- package/test/plugin.3.test.js +50 -72
- package/test/plugin.4.test.js +124 -119
- package/test/promises.test.js +42 -63
- package/test/proto-poisoning.test.js +78 -97
- package/test/register.test.js +8 -18
- package/test/request-error.test.js +57 -146
- package/test/request-id.test.js +30 -49
- package/test/route-hooks.test.js +117 -101
- package/test/route-prefix.test.js +194 -133
- package/test/route-shorthand.test.js +9 -27
- package/test/route.1.test.js +74 -131
- package/test/route.8.test.js +9 -17
- package/test/router-options.test.js +450 -0
- package/test/schema-serialization.test.js +177 -154
- package/test/schema-special-usage.test.js +165 -132
- package/test/schema-validation.test.js +254 -218
- package/test/server.test.js +143 -5
- package/test/set-error-handler.test.js +58 -1
- package/test/skip-reply-send.test.js +64 -69
- package/test/stream.1.test.js +33 -50
- package/test/stream.4.test.js +18 -28
- package/test/stream.5.test.js +11 -19
- package/test/trust-proxy.test.js +32 -58
- package/test/types/errors.test-d.ts +13 -1
- package/test/types/fastify.test-d.ts +3 -0
- package/test/types/request.test-d.ts +1 -0
- package/test/types/type-provider.test-d.ts +55 -0
- package/test/url-rewriting.test.js +45 -62
- package/test/use-semicolon-delimiter.test.js +117 -59
- package/test/versioned-routes.test.js +39 -56
- package/types/errors.d.ts +11 -1
- package/types/hooks.d.ts +1 -1
- package/types/instance.d.ts +1 -1
- package/types/reply.d.ts +2 -2
- package/types/request.d.ts +1 -0
- package/.taprc +0 -7
package/.vscode/settings.json
CHANGED
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
"tab.activeBackground": "#0d0d0d",
|
|
5
5
|
"tab.activeBorder": "#ffff00"
|
|
6
6
|
},
|
|
7
|
-
"activityBar.background": "#
|
|
8
|
-
"activityBar.foreground": "#
|
|
9
|
-
"activityBar.inactiveForeground": "#
|
|
10
|
-
"activityBar.activeBorder": "#
|
|
11
|
-
"activityBar.activeBackground": "#
|
|
12
|
-
"activityBar.border": "#
|
|
13
|
-
"titleBar.activeBackground": "#
|
|
14
|
-
"titleBar.activeForeground": "#
|
|
15
|
-
"titleBar.inactiveBackground": "#
|
|
16
|
-
"titleBar.inactiveForeground": "#
|
|
17
|
-
"titleBar.border": "#
|
|
18
|
-
"statusBar.background": "#
|
|
19
|
-
"statusBar.foreground": "#
|
|
20
|
-
"statusBar.border": "#
|
|
7
|
+
"activityBar.background": "#FBE7B2",
|
|
8
|
+
"activityBar.foreground": "#52358C",
|
|
9
|
+
"activityBar.inactiveForeground": "#616161",
|
|
10
|
+
"activityBar.activeBorder": "#04184d",
|
|
11
|
+
"activityBar.activeBackground": "#C3B48B",
|
|
12
|
+
"activityBar.border": "#C3B48B",
|
|
13
|
+
"titleBar.activeBackground": "#D2BE88",
|
|
14
|
+
"titleBar.activeForeground": "#52358C",
|
|
15
|
+
"titleBar.inactiveBackground": "#bdb59c",
|
|
16
|
+
"titleBar.inactiveForeground": "#616161",
|
|
17
|
+
"titleBar.border": "#C3B48B",
|
|
18
|
+
"statusBar.background": "#E9DBB7",
|
|
19
|
+
"statusBar.foreground": "#52358C",
|
|
20
|
+
"statusBar.border": "#C3B48B"
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
}
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -306,6 +306,8 @@ listed in alphabetical order.
|
|
|
306
306
|
* [__Vincent Le Goff__](https://github.com/zekth)
|
|
307
307
|
* [__Luciano Mammino__](https://github.com/lmammino),
|
|
308
308
|
<https://twitter.com/loige>, <https://www.npmjs.com/~lmammino>
|
|
309
|
+
* [__Jean Michelet__](https://github.com/jean-michelet),
|
|
310
|
+
<https://www.npmjs.com/~jean-michelet>
|
|
309
311
|
* [__KaKa Ng__](https://github.com/climba03003),
|
|
310
312
|
<https://www.npmjs.com/~climba03003>
|
|
311
313
|
* [__Luis Orbaiceta__](https://github.com/luisorbaiceta),
|
package/SECURITY.md
CHANGED
|
@@ -1,4 +1,160 @@
|
|
|
1
1
|
# Security Policy
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
This document describes the management of vulnerabilities for the Fastify
|
|
4
|
+
project and its official plugins.
|
|
5
|
+
|
|
6
|
+
## Reporting vulnerabilities
|
|
7
|
+
|
|
8
|
+
Individuals who find potential vulnerabilities in Fastify are invited to
|
|
9
|
+
complete a vulnerability report via the dedicated pages:
|
|
10
|
+
|
|
11
|
+
1. [HackerOne](https://hackerone.com/fastify)
|
|
12
|
+
2. [GitHub Security Advisory](https://github.com/fastify/fastify/security/advisories/new)
|
|
13
|
+
|
|
14
|
+
### Strict measures when reporting vulnerabilities
|
|
15
|
+
|
|
16
|
+
It is of the utmost importance that you read carefully and follow these
|
|
17
|
+
guidelines to ensure the ecosystem as a whole isn't disrupted due to improperly
|
|
18
|
+
reported vulnerabilities:
|
|
19
|
+
|
|
20
|
+
* Avoid creating new "informative" reports. Only create new
|
|
21
|
+
reports on a vulnerability if you are absolutely sure this should be
|
|
22
|
+
tagged as an actual vulnerability. Third-party vendors and individuals are
|
|
23
|
+
tracking any new vulnerabilities reported in HackerOne or GitHub and will flag
|
|
24
|
+
them as such for their customers (think about snyk, npm audit, ...).
|
|
25
|
+
* Security reports should never be created and triaged by the same person. If
|
|
26
|
+
you are creating a report for a vulnerability that you found, or on
|
|
27
|
+
behalf of someone else, there should always be a 2nd Security Team member who
|
|
28
|
+
triages it. If in doubt, invite more Fastify Collaborators to help triage the
|
|
29
|
+
validity of the report. In any case, the report should follow the same process
|
|
30
|
+
as outlined below of inviting the maintainers to review and accept the
|
|
31
|
+
vulnerability.
|
|
32
|
+
* ***Do not*** attempt to show CI/CD vulnerabilities by creating new pull
|
|
33
|
+
requests to any of the Fastify organization's repositories. Doing so will
|
|
34
|
+
result in a [content report][cr] to GitHub as an unsolicited exploit.
|
|
35
|
+
The proper way to provide such reports is by creating a new repository,
|
|
36
|
+
configured in the same manner as the repository you would like to submit
|
|
37
|
+
a report about, and with a pull request to your own repository showing
|
|
38
|
+
the proof of concept.
|
|
39
|
+
|
|
40
|
+
[cr]: https://docs.github.com/en/communities/maintaining-your-safety-on-github/reporting-abuse-or-spam#reporting-an-issue-or-pull-request
|
|
41
|
+
|
|
42
|
+
### Vulnerabilities found outside this process
|
|
43
|
+
|
|
44
|
+
â The Fastify project does not support any reporting outside the process mentioned
|
|
45
|
+
in this document.
|
|
46
|
+
|
|
47
|
+
## Handling vulnerability reports
|
|
48
|
+
|
|
49
|
+
When a potential vulnerability is reported, the following actions are taken:
|
|
50
|
+
|
|
51
|
+
### Triage
|
|
52
|
+
|
|
53
|
+
**Delay:** 4 business days
|
|
54
|
+
|
|
55
|
+
Within 4 business days, a member of the security team provides a first answer to
|
|
56
|
+
the individual who submitted the potential vulnerability. The possible responses
|
|
57
|
+
can be:
|
|
58
|
+
|
|
59
|
+
* **Acceptance**: what was reported is considered as a new vulnerability
|
|
60
|
+
* **Rejection**: what was reported is not considered as a new vulnerability
|
|
61
|
+
* **Need more information**: the security team needs more information in order to
|
|
62
|
+
evaluate what was reported.
|
|
63
|
+
|
|
64
|
+
Triaging should include updating issue fields:
|
|
65
|
+
* Asset - set/create the module affected by the report
|
|
66
|
+
* Severity - TBD, currently left empty
|
|
67
|
+
|
|
68
|
+
Reference: [HackerOne: Submitting
|
|
69
|
+
Reports](https://docs.hackerone.com/hackers/submitting-reports.html)
|
|
70
|
+
|
|
71
|
+
### Correction follow-up
|
|
72
|
+
|
|
73
|
+
**Delay:** 90 days
|
|
74
|
+
|
|
75
|
+
When a vulnerability is confirmed, a member of the security team volunteers to
|
|
76
|
+
follow up on this report.
|
|
77
|
+
|
|
78
|
+
With the help of the individual who reported the vulnerability, they contact the
|
|
79
|
+
maintainers of the vulnerable package to make them aware of the vulnerability.
|
|
80
|
+
The maintainers can be invited as participants to the reported issue.
|
|
81
|
+
|
|
82
|
+
With the package maintainer, they define a release date for the publication of
|
|
83
|
+
the vulnerability. Ideally, this release date should not happen before the
|
|
84
|
+
package has been patched.
|
|
85
|
+
|
|
86
|
+
The report's vulnerable versions upper limit should be set to:
|
|
87
|
+
* `*` if there is no fixed version available by the time of publishing the
|
|
88
|
+
report.
|
|
89
|
+
* the last vulnerable version. For example: `<=1.2.3` if a fix exists in `1.2.4`
|
|
90
|
+
|
|
91
|
+
### Publication
|
|
92
|
+
|
|
93
|
+
**Delay:** 90 days
|
|
94
|
+
|
|
95
|
+
Within 90 days after the triage date, the vulnerability must be made public.
|
|
96
|
+
|
|
97
|
+
**Severity**: Vulnerability severity is assessed using [CVSS
|
|
98
|
+
v.3](https://www.first.org/cvss/user-guide). More information can be found on
|
|
99
|
+
[HackerOne documentation](https://docs.hackerone.com/hackers/severity.html)
|
|
100
|
+
|
|
101
|
+
If the package maintainer is actively developing a patch, an additional delay
|
|
102
|
+
can be added with the approval of the security team and the individual who
|
|
103
|
+
reported the vulnerability.
|
|
104
|
+
|
|
105
|
+
At this point, a CVE should be requested through the selected platform through
|
|
106
|
+
the UI, which should include the Report ID and a summary.
|
|
107
|
+
|
|
108
|
+
Within HackerOne, this is handled through a "public disclosure request".
|
|
109
|
+
|
|
110
|
+
Reference: [HackerOne:
|
|
111
|
+
Disclosure](https://docs.hackerone.com/hackers/disclosure.html)
|
|
112
|
+
|
|
113
|
+
## The Fastify Security team
|
|
114
|
+
|
|
115
|
+
The core team is responsible for the management of the security program and
|
|
116
|
+
this policy and process.
|
|
117
|
+
|
|
118
|
+
Members of this team are expected to keep all information that they have
|
|
119
|
+
privileged access to by being on the team completely private to the team. This
|
|
120
|
+
includes agreeing to not notify anyone outside the team of issues that have not
|
|
121
|
+
yet been disclosed publicly, including the existence of issues, expectations of
|
|
122
|
+
upcoming releases, and patching of any issues other than in the process of their
|
|
123
|
+
work as a member of the Fastify Core team.
|
|
124
|
+
|
|
125
|
+
### Members
|
|
126
|
+
|
|
127
|
+
* [__Matteo Collina__](https://github.com/mcollina),
|
|
128
|
+
<https://twitter.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
|
|
129
|
+
* [__Tomas Della Vedova__](https://github.com/delvedor),
|
|
130
|
+
<https://twitter.com/delvedor>, <https://www.npmjs.com/~delvedor>
|
|
131
|
+
* [__Vincent Le Goff__](https://github.com/zekth)
|
|
132
|
+
* [__KaKa Ng__](https://github.com/climba03003)
|
|
133
|
+
* [__James Sumners__](https://github.com/jsumners),
|
|
134
|
+
<https://twitter.com/jsumners79>, <https://www.npmjs.com/~jsumners>
|
|
135
|
+
|
|
136
|
+
## OpenSSF CII Best Practices
|
|
137
|
+
|
|
138
|
+
[](https://bestpractices.coreinfrastructure.org/projects/7585)
|
|
139
|
+
|
|
140
|
+
There are three âtiersâ: passing, silver, and gold.
|
|
141
|
+
|
|
142
|
+
### Passing
|
|
143
|
+
We meet 100% of the âpassingâ criteria.
|
|
144
|
+
|
|
145
|
+
### Silver
|
|
146
|
+
We meet 87% of the âsilverâ criteria. The gaps are as follows:
|
|
147
|
+
- we do not have a DCO or a CLA process for contributions.
|
|
148
|
+
- we do not currently document
|
|
149
|
+
âwhat the user can and cannot expect in terms of securityâ for our project.
|
|
150
|
+
- we do not currently document âthe architecture (aka high-level design)â
|
|
151
|
+
for our project.
|
|
152
|
+
|
|
153
|
+
### Gold
|
|
154
|
+
We meet 70% of the âgoldâ criteria. The gaps are as follows:
|
|
155
|
+
- we do not yet have the âsilverâ badge; see all the gaps above.
|
|
156
|
+
- We do not include a copyright or license statement in each source file.
|
|
157
|
+
Efforts are underway to change this archaic practice into a
|
|
158
|
+
suggestion instead of a hard requirement.
|
|
159
|
+
- There are a few unanswered questions around cryptography that are
|
|
160
|
+
waiting for clarification.
|
|
@@ -42,7 +42,15 @@ const defaultInitOptions = {
|
|
|
42
42
|
requestIdLogLabel: 'reqId',
|
|
43
43
|
http2SessionTimeout: 72000, // 72 seconds
|
|
44
44
|
exposeHeadRoutes: true,
|
|
45
|
-
useSemicolonDelimiter: false
|
|
45
|
+
useSemicolonDelimiter: false,
|
|
46
|
+
allowErrorHandlerOverride: true, // TODO: set to false in v6
|
|
47
|
+
routerOptions: {
|
|
48
|
+
ignoreTrailingSlash: false,
|
|
49
|
+
ignoreDuplicateSlashes: false,
|
|
50
|
+
maxParamLength: 100,
|
|
51
|
+
allowUnsafeRegex: false,
|
|
52
|
+
useSemicolonDelimiter: false
|
|
53
|
+
}
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
const schema = {
|
|
@@ -102,6 +110,17 @@ const schema = {
|
|
|
102
110
|
http2SessionTimeout: { type: 'integer', default: defaultInitOptions.http2SessionTimeout },
|
|
103
111
|
exposeHeadRoutes: { type: 'boolean', default: defaultInitOptions.exposeHeadRoutes },
|
|
104
112
|
useSemicolonDelimiter: { type: 'boolean', default: defaultInitOptions.useSemicolonDelimiter },
|
|
113
|
+
routerOptions: {
|
|
114
|
+
type: 'object',
|
|
115
|
+
additionalProperties: false,
|
|
116
|
+
properties: {
|
|
117
|
+
ignoreTrailingSlash: { type: 'boolean', default: defaultInitOptions.routerOptions.ignoreTrailingSlash },
|
|
118
|
+
ignoreDuplicateSlashes: { type: 'boolean', default: defaultInitOptions.routerOptions.ignoreDuplicateSlashes },
|
|
119
|
+
maxParamLength: { type: 'integer', default: defaultInitOptions.routerOptions.maxParamLength },
|
|
120
|
+
allowUnsafeRegex: { type: 'boolean', default: defaultInitOptions.routerOptions.allowUnsafeRegex },
|
|
121
|
+
useSemicolonDelimiter: { type: 'boolean', default: defaultInitOptions.routerOptions.useSemicolonDelimiter }
|
|
122
|
+
}
|
|
123
|
+
},
|
|
105
124
|
constraints: {
|
|
106
125
|
type: 'object',
|
|
107
126
|
additionalProperties: {
|
|
@@ -527,11 +527,14 @@ Retry-After: 5000
|
|
|
527
527
|
Then we attempted a new request (`req-2`), which was a `GET /ping`. As expected,
|
|
528
528
|
since that was not one of the requests we asked our plugin to filter, it
|
|
529
529
|
succeeded. That could also be used as a means of informing an interested party
|
|
530
|
-
whether or not we were ready to serve requests
|
|
531
|
-
commonly associated with *liveness* checks and that would be
|
|
532
|
-
of a *readiness* check
|
|
533
|
-
|
|
534
|
-
|
|
530
|
+
whether or not we were ready to serve requests with the `ready` field. Although
|
|
531
|
+
`/ping` is more commonly associated with *liveness* checks and that would be
|
|
532
|
+
the responsibility of a *readiness* check. The curious reader can get more info
|
|
533
|
+
on these terms in the article
|
|
534
|
+
["Kubernetes best practices: Setting up health checks with readiness and liveness probes"](
|
|
535
|
+
https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-setting-up-health-checks-with-readiness-and-liveness-probes).
|
|
536
|
+
|
|
537
|
+
Below is the response to that request:
|
|
535
538
|
|
|
536
539
|
```sh
|
|
537
540
|
HTTP/1.1 200 OK
|
package/docs/Guides/Ecosystem.md
CHANGED
|
@@ -152,6 +152,15 @@ section.
|
|
|
152
152
|
|
|
153
153
|
#### [Community](#community)
|
|
154
154
|
|
|
155
|
+
> âšī¸ Note:
|
|
156
|
+
> Fastify community plugins are part of the broader community efforts,
|
|
157
|
+
> and we are thankful for these contributions. However, they are not
|
|
158
|
+
> maintained by the Fastify team.
|
|
159
|
+
> Use them at your own discretion.
|
|
160
|
+
> If you find malicious code, please
|
|
161
|
+
> [open an issue](https://github.com/fastify/fastify/issues/new/choose) or
|
|
162
|
+
> submit a PR to remove the plugin from the list.
|
|
163
|
+
|
|
155
164
|
- [`@aaroncadillac/crudify-mongo`](https://github.com/aaroncadillac/crudify-mongo)
|
|
156
165
|
A simple way to add a crud in your fastify project.
|
|
157
166
|
- [`@applicazza/fastify-nextjs`](https://github.com/applicazza/fastify-nextjs)
|
|
@@ -190,14 +199,11 @@ section.
|
|
|
190
199
|
Run REST APIs and other web applications using your existing Node.js
|
|
191
200
|
application framework (Express, Koa, Hapi and Fastify), on top of AWS Lambda,
|
|
192
201
|
Huawei and many other clouds.
|
|
202
|
+
- [`@hey-api/openapi-ts`](https://heyapi.dev/openapi-ts/plugins/fastify)
|
|
203
|
+
The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more.
|
|
193
204
|
- [`@immobiliarelabs/fastify-metrics`](https://github.com/immobiliare/fastify-metrics)
|
|
194
205
|
Minimalistic and opinionated plugin that collects usage/process metrics and
|
|
195
206
|
dispatches to [statsd](https://github.com/statsd/statsd).
|
|
196
|
-
- [`@immobiliarelabs/fastify-sentry`](https://github.com/immobiliare/fastify-sentry)
|
|
197
|
-
Sentry errors handler that just works! Install, add your DSN and you're good
|
|
198
|
-
to go!
|
|
199
|
-
A plugin to implement [Lyra](https://github.com/nearform/lyra) search engine
|
|
200
|
-
on Fastify
|
|
201
207
|
- [`@inaiat/fastify-papr`](https://github.com/inaiat/fastify-papr)
|
|
202
208
|
A plugin to integrate [Papr](https://github.com/plexinc/papr),
|
|
203
209
|
the MongoDB ORM for TypeScript & MongoDB, with Fastify.
|
|
@@ -503,6 +509,8 @@ middlewares into Fastify plugins
|
|
|
503
509
|
[MS Graph Change Notifications webhooks](https://learn.microsoft.com/it-it/graph/change-notifications-delivery-webhooks?tabs=http).
|
|
504
510
|
- [`fastify-multer`](https://github.com/fox1t/fastify-multer) Multer is a plugin
|
|
505
511
|
for handling multipart/form-data, which is primarily used for uploading files.
|
|
512
|
+
- [`fastify-multilingual`](https://github.com/gbrugger/fastify-multilingual) Unobtrusively
|
|
513
|
+
decorates fastify request with Polyglot.js for i18n.
|
|
506
514
|
- [`fastify-nats`](https://github.com/mahmed8003/fastify-nats) Plugin to share
|
|
507
515
|
[NATS](https://nats.io) client across Fastify.
|
|
508
516
|
- [`fastify-next-auth`](https://github.com/wobsoriano/fastify-next-auth)
|
|
@@ -553,6 +561,9 @@ middlewares into Fastify plugins
|
|
|
553
561
|
A set of Fastify plugins to integrate Apple Wallet Web Service specification
|
|
554
562
|
- [`fastify-peekaboo`](https://github.com/simone-sanfratello/fastify-peekaboo)
|
|
555
563
|
Fastify plugin for memoize responses by expressive settings.
|
|
564
|
+
- [`fastify-permissions`](https://github.com/pckrishnadas88/fastify-permissions)
|
|
565
|
+
Route-level permission middleware for Fastify supports
|
|
566
|
+
custom permission checks.
|
|
556
567
|
- [`fastify-piscina`](https://github.com/piscinajs/fastify-piscina) A worker
|
|
557
568
|
thread pool plugin using [Piscina](https://github.com/piscinajs/piscina).
|
|
558
569
|
- [`fastify-polyglot`](https://github.com/beliven-it/fastify-polyglot) A plugin to
|
|
@@ -612,6 +623,9 @@ middlewares into Fastify plugins
|
|
|
612
623
|
Fastify Rob-Config integration.
|
|
613
624
|
- [`fastify-route-group`](https://github.com/TakNePoidet/fastify-route-group)
|
|
614
625
|
Convenient grouping and inheritance of routes.
|
|
626
|
+
- [`fastify-route-preset`](https://github.com/inyourtime/fastify-route-preset)
|
|
627
|
+
A Fastify plugin that enables you to create route configurations that can be
|
|
628
|
+
applied to multiple routes.
|
|
615
629
|
- [`fastify-s3-buckets`](https://github.com/kibertoad/fastify-s3-buckets)
|
|
616
630
|
Ensure the existence of defined S3 buckets on the application startup.
|
|
617
631
|
- [`fastify-schema-constraint`](https://github.com/Eomm/fastify-schema-constraint)
|
|
@@ -730,6 +744,7 @@ middlewares into Fastify plugins
|
|
|
730
744
|
- [`typeorm-fastify-plugin`](https://github.com/jclemens24/fastify-typeorm) A simple
|
|
731
745
|
and updated Typeorm plugin for use with Fastify.
|
|
732
746
|
|
|
747
|
+
|
|
733
748
|
#### [Community Tools](#community-tools)
|
|
734
749
|
|
|
735
750
|
- [`@fastify-userland/workflows`](https://github.com/fastify-userland/workflows)
|
|
@@ -557,7 +557,6 @@ and provides a way to trace the lifecycle of a request.
|
|
|
557
557
|
'use strict'
|
|
558
558
|
|
|
559
559
|
const diagnostics = require('node:diagnostics_channel')
|
|
560
|
-
const sget = require('simple-get').concat
|
|
561
560
|
const Fastify = require('fastify')
|
|
562
561
|
|
|
563
562
|
diagnostics.subscribe('tracing:fastify.request.handler:start', (msg) => {
|
|
@@ -583,15 +582,12 @@ fastify.route({
|
|
|
583
582
|
}
|
|
584
583
|
})
|
|
585
584
|
|
|
586
|
-
fastify.listen({ port: 0 }, function () {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
t.equal(response.statusCode, 200)
|
|
593
|
-
t.same(JSON.parse(body), { hello: 'world' })
|
|
594
|
-
})
|
|
585
|
+
fastify.listen({ port: 0 }, async function () {
|
|
586
|
+
const result = await fetch(fastify.listeningOrigin + '/7')
|
|
587
|
+
|
|
588
|
+
t.assert.ok(result.ok)
|
|
589
|
+
t.assert.strictEqual(response.status, 200)
|
|
590
|
+
t.assert.deepStrictEqual(await result.json(), { hello: 'world' })
|
|
595
591
|
})
|
|
596
592
|
```
|
|
597
593
|
|
|
@@ -285,7 +285,7 @@ server {
|
|
|
285
285
|
## Kubernetes
|
|
286
286
|
<a id="kubernetes"></a>
|
|
287
287
|
|
|
288
|
-
The `readinessProbe` uses [
|
|
288
|
+
The `readinessProbe` uses ([by
|
|
289
289
|
default](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#configure-probes))
|
|
290
290
|
the pod IP as the hostname. Fastify listens on `127.0.0.1` by default. The probe
|
|
291
291
|
will not be able to reach the application in this case. To make it work,
|
|
@@ -152,7 +152,7 @@ fastify.addContentTypeParser('text/xml', function (request, payload, done) {
|
|
|
152
152
|
})
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
-
>
|
|
155
|
+
> âšī¸ Note: `function(req, done)` and `async function(req)` are
|
|
156
156
|
> still supported but deprecated.
|
|
157
157
|
|
|
158
158
|
#### Body Parser
|
package/docs/Reference/Errors.md
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
- [FST_ERR_CTP_INVALID_MEDIA_TYPE](#fst_err_ctp_invalid_media_type)
|
|
30
30
|
- [FST_ERR_CTP_INVALID_CONTENT_LENGTH](#fst_err_ctp_invalid_content_length)
|
|
31
31
|
- [FST_ERR_CTP_EMPTY_JSON_BODY](#fst_err_ctp_empty_json_body)
|
|
32
|
+
- [FST_ERR_CTP_INVALID_JSON_BODY](#fst_err_ctp_invalid_json_body)
|
|
32
33
|
- [FST_ERR_CTP_INSTANCE_ALREADY_STARTED](#fst_err_ctp_instance_already_started)
|
|
33
34
|
- [FST_ERR_INSTANCE_ALREADY_LISTENING](#fst_err_instance_already_listening)
|
|
34
35
|
- [FST_ERR_DEC_ALREADY_PRESENT](#fst_err_dec_already_present)
|
|
@@ -97,6 +98,7 @@
|
|
|
97
98
|
- [FST_ERR_VALIDATION](#fst_err_validation)
|
|
98
99
|
- [FST_ERR_LISTEN_OPTIONS_INVALID](#fst_err_listen_options_invalid)
|
|
99
100
|
- [FST_ERR_ERROR_HANDLER_NOT_FN](#fst_err_error_handler_not_fn)
|
|
101
|
+
- [FST_ERR_ERROR_HANDLER_ALREADY_SET](#fst_err_error_handler_already_set)
|
|
100
102
|
|
|
101
103
|
### Error Handling In Node.js
|
|
102
104
|
<a id="error-handling"></a>
|
|
@@ -298,7 +300,8 @@ Below is a table with all the error codes used by Fastify.
|
|
|
298
300
|
| <a id="fst_err_ctp_body_too_large">FST_ERR_CTP_BODY_TOO_LARGE</a> | The request body is larger than the provided limit. | Increase the limit in the Fastify server instance setting: [bodyLimit](./Server.md#bodylimit) | [#1168](https://github.com/fastify/fastify/pull/1168) |
|
|
299
301
|
| <a id="fst_err_ctp_invalid_media_type">FST_ERR_CTP_INVALID_MEDIA_TYPE</a> | The received media type is not supported (i.e. there is no suitable `Content-Type` parser for it). | Use a different content type. | [#1168](https://github.com/fastify/fastify/pull/1168) |
|
|
300
302
|
| <a id="fst_err_ctp_invalid_content_length">FST_ERR_CTP_INVALID_CONTENT_LENGTH</a> | Request body size did not match <code>Content-Length</code>. | Check the request body size and the <code>Content-Length</code> header. | [#1168](https://github.com/fastify/fastify/pull/1168) |
|
|
301
|
-
| <a id="fst_err_ctp_empty_json_body">FST_ERR_CTP_EMPTY_JSON_BODY</a> | Body
|
|
303
|
+
| <a id="fst_err_ctp_empty_json_body">FST_ERR_CTP_EMPTY_JSON_BODY</a> | Body is not valid JSON but content-type is set to <code>application/json</code>. | Check if the request body is valid JSON. | [#5925](https://github.com/fastify/fastify/pull/5925) |
|
|
304
|
+
| <a id="fst_err_ctp_invalid_json_body">FST_ERR_CTP_INVALID_JSON_BODY</a> | Body cannot be empty when content-type is set to <code>application/json</code>. | Check the request body. | [#1253](https://github.com/fastify/fastify/pull/1253) |
|
|
302
305
|
| <a id="fst_err_ctp_instance_already_started">FST_ERR_CTP_INSTANCE_ALREADY_STARTED</a> | Fastify is already started. | - | [#4554](https://github.com/fastify/fastify/pull/4554) |
|
|
303
306
|
| <a id="fst_err_instance_already_listening">FST_ERR_INSTANCE_ALREADY_LISTENING</a> | Fastify instance is already listening. | - | [#4554](https://github.com/fastify/fastify/pull/4554) |
|
|
304
307
|
| <a id="fst_err_dec_already_present">FST_ERR_DEC_ALREADY_PRESENT</a> | A decorator with the same name is already registered. | Use a different decorator name. | [#1168](https://github.com/fastify/fastify/pull/1168) |
|
|
@@ -366,5 +369,4 @@ Below is a table with all the error codes used by Fastify.
|
|
|
366
369
|
| <a id="fst_err_plugin_invalid_async_handler">FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER</a> | The plugin being registered mixes async and callback styles. | - | [#5141](https://github.com/fastify/fastify/pull/5141) |
|
|
367
370
|
| <a id="fst_err_validation">FST_ERR_VALIDATION</a> | The Request failed the payload validation. | Check the request payload. | [#4824](https://github.com/fastify/fastify/pull/4824) |
|
|
368
371
|
| <a id="fst_err_listen_options_invalid">FST_ERR_LISTEN_OPTIONS_INVALID</a> | Invalid listen options. | Check the listen options. | [#4886](https://github.com/fastify/fastify/pull/4886) |
|
|
369
|
-
| <a id="fst_err_error_handler_not_fn">FST_ERR_ERROR_HANDLER_NOT_FN</a> | Error Handler must be a function | Provide a function to `setErrorHandler`. | [#5317](https://github.com/fastify/fastify/pull/5317) |
|
|
370
|
-
|
|
372
|
+
| <a id="fst_err_error_handler_not_fn">FST_ERR_ERROR_HANDLER_NOT_FN</a> | Error Handler must be a function | Provide a function to `setErrorHandler`. | [#5317](https://github.com/fastify/fastify/pull/5317) | <a id="fst_err_error_handler_already_set">FST_ERR_ERROR_HANDLER_ALREADY_SET</a> | Error Handler already set in this scope. Set `allowErrorHandlerOverride: true` to allow overriding. | By default, `setErrorHandler` can only be called once per encapsulation context. | [#6097](https://github.com/fastify/fastify/pull/6098) |
|
package/docs/Reference/Hooks.md
CHANGED
|
@@ -34,7 +34,7 @@ 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
|
-
>
|
|
37
|
+
> âšī¸ Note: The `done` callback is not available when using `async`/`await` or
|
|
38
38
|
> returning a `Promise`. If you do invoke a `done` callback in this situation
|
|
39
39
|
> unexpected behavior may occur, e.g. duplicate invocation of handlers.
|
|
40
40
|
|
|
@@ -68,7 +68,7 @@ fastify.addHook('onRequest', async (request, reply) => {
|
|
|
68
68
|
})
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
>
|
|
71
|
+
> âšī¸ Note: In the [onRequest](#onrequest) hook, `request.body` will always be
|
|
72
72
|
> `undefined`, because the body parsing happens before the
|
|
73
73
|
> [preValidation](#prevalidation) hook.
|
|
74
74
|
|
|
@@ -98,16 +98,16 @@ fastify.addHook('preParsing', async (request, reply, payload) => {
|
|
|
98
98
|
})
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
>
|
|
101
|
+
> âšī¸ Note: In the [preParsing](#preparsing) hook, `request.body` will always be
|
|
102
102
|
> `undefined`, because the body parsing happens before the
|
|
103
103
|
> [preValidation](#prevalidation) hook.
|
|
104
104
|
|
|
105
|
-
>
|
|
105
|
+
> âšī¸ Note: You should also add a `receivedEncodedLength` property to the
|
|
106
106
|
> returned stream. This property is used to correctly match the request payload
|
|
107
107
|
> with the `Content-Length` header value. Ideally, this property should be updated
|
|
108
108
|
> on each received chunk.
|
|
109
109
|
|
|
110
|
-
>
|
|
110
|
+
> âšī¸ Note: The size of the returned stream is checked to not exceed the limit
|
|
111
111
|
> set in [`bodyLimit`](./Server.md#bodylimit) option.
|
|
112
112
|
|
|
113
113
|
### preValidation
|
|
@@ -166,7 +166,7 @@ fastify.addHook('preSerialization', async (request, reply, payload) => {
|
|
|
166
166
|
})
|
|
167
167
|
```
|
|
168
168
|
|
|
169
|
-
>
|
|
169
|
+
> âšī¸ Note: The hook is NOT called if the payload is a `string`, a `Buffer`, a
|
|
170
170
|
> `stream`, or `null`.
|
|
171
171
|
|
|
172
172
|
### onError
|
|
@@ -189,14 +189,10 @@ specific header in case of error.
|
|
|
189
189
|
It is not intended for changing the error, and calling `reply.send` will throw
|
|
190
190
|
an exception.
|
|
191
191
|
|
|
192
|
-
This hook will be executed
|
|
193
|
-
the [Custom Error Handler set by `setErrorHandler`](./Server.md#seterrorhandler)
|
|
194
|
-
has been executed, and only if the custom error handler sends an error back to the
|
|
195
|
-
user
|
|
196
|
-
*(Note that the default error handler always sends the error back to the
|
|
197
|
-
user)*.
|
|
192
|
+
This hook will be executed before
|
|
193
|
+
the [Custom Error Handler set by `setErrorHandler`](./Server.md#seterrorhandler).
|
|
198
194
|
|
|
199
|
-
>
|
|
195
|
+
> âšī¸ Note: Unlike the other hooks, passing an error to the `done` function is not
|
|
200
196
|
> supported.
|
|
201
197
|
|
|
202
198
|
### onSend
|
|
@@ -233,7 +229,7 @@ fastify.addHook('onSend', (request, reply, payload, done) => {
|
|
|
233
229
|
> to `0`, whereas the `Content-Length` header will not be set if the payload is
|
|
234
230
|
> `null`.
|
|
235
231
|
|
|
236
|
-
>
|
|
232
|
+
> âšī¸ Note: If you change the payload, you may only change it to a `string`, a
|
|
237
233
|
> `Buffer`, a `stream`, a `ReadableStream`, a `Response`, or `null`.
|
|
238
234
|
|
|
239
235
|
|
|
@@ -256,7 +252,7 @@ The `onResponse` hook is executed when a response has been sent, so you will not
|
|
|
256
252
|
be able to send more data to the client. It can however be useful for sending
|
|
257
253
|
data to external services, for example, to gather statistics.
|
|
258
254
|
|
|
259
|
-
>
|
|
255
|
+
> âšī¸ Note: Setting `disableRequestLogging` to `true` will disable any error log
|
|
260
256
|
> inside the `onResponse` hook. In this case use `try - catch` to log errors.
|
|
261
257
|
|
|
262
258
|
### onTimeout
|
|
@@ -298,7 +294,7 @@ The `onRequestAbort` hook is executed when a client closes the connection before
|
|
|
298
294
|
the entire request has been processed. Therefore, you will not be able to send
|
|
299
295
|
data to the client.
|
|
300
296
|
|
|
301
|
-
>
|
|
297
|
+
> âšī¸ Note: Client abort detection is not completely reliable.
|
|
302
298
|
> See: [`Detecting-When-Clients-Abort.md`](../Guides/Detecting-When-Clients-Abort.md)
|
|
303
299
|
|
|
304
300
|
### Manage Errors from a hook
|
|
@@ -452,7 +448,7 @@ fastify.addHook('onListen', async function () {
|
|
|
452
448
|
})
|
|
453
449
|
```
|
|
454
450
|
|
|
455
|
-
>
|
|
451
|
+
> âšī¸ Note: This hook will not run when the server is started using
|
|
456
452
|
> fastify.inject()` or `fastify.ready()`.
|
|
457
453
|
|
|
458
454
|
### onClose
|
|
@@ -576,7 +572,7 @@ This hook can be useful if you are developing a plugin that needs to know when a
|
|
|
576
572
|
plugin context is formed, and you want to operate in that specific context, thus
|
|
577
573
|
this hook is encapsulated.
|
|
578
574
|
|
|
579
|
-
>
|
|
575
|
+
> âšī¸ Note: This hook will not be called if a plugin is wrapped inside
|
|
580
576
|
> [`fastify-plugin`](https://github.com/fastify/fastify-plugin).
|
|
581
577
|
```js
|
|
582
578
|
fastify.decorate('data', [])
|
|
@@ -774,7 +770,7 @@ fastify.route({
|
|
|
774
770
|
})
|
|
775
771
|
```
|
|
776
772
|
|
|
777
|
-
>
|
|
773
|
+
> âšī¸ Note: Both options also accept an array of functions.
|
|
778
774
|
|
|
779
775
|
## Using Hooks to Inject Custom Properties
|
|
780
776
|
<a id="using-hooks-to-inject-custom-properties"></a>
|
|
@@ -861,7 +857,7 @@ channel.subscribe(function ({ fastify }) {
|
|
|
861
857
|
})
|
|
862
858
|
```
|
|
863
859
|
|
|
864
|
-
>
|
|
860
|
+
> âšī¸ Note: The TracingChannel class API is currently experimental and may undergo
|
|
865
861
|
> breaking changes even in semver-patch releases of Node.js.
|
|
866
862
|
|
|
867
863
|
Five other events are published on a per-request basis following the
|
|
@@ -70,9 +70,9 @@ submitted, the data flow is as follows:
|
|
|
70
70
|
â
send or return â â
|
|
71
71
|
â â â
|
|
72
72
|
â âŧ â
|
|
73
|
-
reply sent âââ JSON ââ´â Error instance âââļ
|
|
73
|
+
reply sent âââ JSON ââ´â Error instance âââļ onError Hook âââââââââ
|
|
74
74
|
â
|
|
75
|
-
reply sent âââ JSON ââ´â Error instance âââļ
|
|
75
|
+
reply sent âââ JSON ââ´â Error instance âââļ setErrorHandler
|
|
76
76
|
â
|
|
77
77
|
âââļ reply sent
|
|
78
78
|
```
|
|
@@ -157,7 +157,7 @@ const fastify = require('fastify')({
|
|
|
157
157
|
});
|
|
158
158
|
```
|
|
159
159
|
|
|
160
|
-
>
|
|
160
|
+
> âšī¸ Note: In some cases, the [`Reply`](./Reply.md) object passed to the `res`
|
|
161
161
|
> serializer cannot be fully constructed. When writing a custom `res`
|
|
162
162
|
> serializer, check for the existence of any properties on `reply` aside from
|
|
163
163
|
> `statusCode`, which is always present. For example, verify the existence of
|
|
@@ -184,7 +184,7 @@ const fastify = require('fastify')({
|
|
|
184
184
|
});
|
|
185
185
|
```
|
|
186
186
|
|
|
187
|
-
>
|
|
187
|
+
> âšī¸ Note: The body cannot be serialized inside a `req` method because the
|
|
188
188
|
request is serialized when the child logger is created. At that time, the body
|
|
189
189
|
is not yet parsed.
|
|
190
190
|
|
|
@@ -199,7 +199,7 @@ app.addHook('preHandler', function (req, reply, done) {
|
|
|
199
199
|
})
|
|
200
200
|
```
|
|
201
201
|
|
|
202
|
-
>
|
|
202
|
+
> âšī¸ Note: Ensure serializers never throw errors, as this can cause the Node
|
|
203
203
|
> process to exit. See the
|
|
204
204
|
> [Pino documentation](https://getpino.io/#/docs/api?id=opt-serializers) for more
|
|
205
205
|
> information.
|
|
@@ -50,7 +50,7 @@ that already has the Fastify [Request](./Request.md#request) and
|
|
|
50
50
|
To run middleware under certain paths, pass the path as the first parameter to
|
|
51
51
|
`use`.
|
|
52
52
|
|
|
53
|
-
>
|
|
53
|
+
> âšī¸ Note: This does not support routes with parameters
|
|
54
54
|
> (e.g. `/user/:id/comments`) and wildcards are not supported in multiple paths.
|
|
55
55
|
|
|
56
56
|
```js
|