fastify 5.4.0 → 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 +22 -0
- package/LICENSE +1 -1
- package/SECURITY.md +158 -2
- package/build/build-validation.js +19 -1
- package/docs/Guides/Delay-Accepting-Requests.md +8 -5
- package/docs/Guides/Ecosystem.md +11 -0
- package/docs/Guides/Migration-Guide-V5.md +6 -10
- package/docs/Guides/Recommendations.md +1 -1
- package/docs/Reference/Errors.md +3 -1
- package/docs/Reference/Hooks.md +2 -6
- package/docs/Reference/Lifecycle.md +2 -2
- package/docs/Reference/Request.md +1 -1
- package/docs/Reference/Routes.md +4 -3
- package/docs/Reference/Server.md +306 -179
- package/docs/Reference/TypeScript.md +1 -3
- package/docs/Reference/Validation-and-Serialization.md +55 -3
- package/docs/Reference/Warnings.md +2 -1
- package/fastify.d.ts +2 -2
- package/fastify.js +34 -33
- package/lib/configValidator.js +196 -28
- package/lib/contentTypeParser.js +41 -48
- package/lib/error-handler.js +3 -3
- package/lib/errors.js +5 -0
- package/lib/handleRequest.js +13 -17
- package/lib/promise.js +23 -0
- package/lib/reply.js +17 -19
- package/lib/route.js +37 -3
- package/lib/server.js +36 -35
- package/lib/warnings.js +11 -1
- package/package.json +7 -7
- package/test/async-await.test.js +81 -134
- package/test/async_hooks.test.js +18 -37
- package/test/body-limit.test.js +51 -0
- package/test/buffer.test.js +22 -0
- 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.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.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-request.test.js +8 -16
- package/test/diagnostics-channel/error-request.test.js +7 -15
- 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 +138 -134
- package/test/hooks-async.test.js +26 -32
- package/test/hooks.test.js +261 -447
- 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/mkcalendar.test.js +45 -72
- package/test/http-methods/move.test.js +6 -10
- package/test/http-methods/propfind.test.js +34 -44
- package/test/http-methods/unlock.test.js +5 -9
- package/test/http2/secure-with-fallback.test.js +3 -1
- package/test/https/custom-https-server.test.js +9 -13
- package/test/input-validation.js +139 -150
- package/test/internals/errors.test.js +50 -1
- package/test/internals/handle-request.test.js +29 -5
- package/test/internals/promise.test.js +63 -0
- package/test/internals/reply.test.js +277 -496
- package/test/plugin.1.test.js +40 -68
- package/test/plugin.2.test.js +40 -70
- package/test/plugin.3.test.js +25 -68
- package/test/promises.test.js +42 -63
- package/test/register.test.js +8 -18
- package/test/request-error.test.js +57 -100
- package/test/request-id.test.js +30 -49
- package/test/route-hooks.test.js +12 -16
- 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-validation.test.js +30 -31
- package/test/server.test.js +143 -5
- 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/types/errors.test-d.ts +13 -1
- package/test/types/type-provider.test-d.ts +55 -0
- 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
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"workbench.colorCustomizations": {
|
|
3
|
+
"[GitHub Dark]": {
|
|
4
|
+
"tab.activeBackground": "#0d0d0d",
|
|
5
|
+
"tab.activeBorder": "#ffff00"
|
|
6
|
+
},
|
|
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
|
+
}
|
|
22
|
+
}
|
package/LICENSE
CHANGED
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.
|
|
@@ -43,7 +43,14 @@ const defaultInitOptions = {
|
|
|
43
43
|
http2SessionTimeout: 72000, // 72 seconds
|
|
44
44
|
exposeHeadRoutes: true,
|
|
45
45
|
useSemicolonDelimiter: false,
|
|
46
|
-
allowErrorHandlerOverride: true // TODO: set to false in v6
|
|
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
|
+
}
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
const schema = {
|
|
@@ -103,6 +110,17 @@ const schema = {
|
|
|
103
110
|
http2SessionTimeout: { type: 'integer', default: defaultInitOptions.http2SessionTimeout },
|
|
104
111
|
exposeHeadRoutes: { type: 'boolean', default: defaultInitOptions.exposeHeadRoutes },
|
|
105
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
|
+
},
|
|
106
124
|
constraints: {
|
|
107
125
|
type: 'object',
|
|
108
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
|
@@ -199,6 +199,8 @@ section.
|
|
|
199
199
|
Run REST APIs and other web applications using your existing Node.js
|
|
200
200
|
application framework (Express, Koa, Hapi and Fastify), on top of AWS Lambda,
|
|
201
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.
|
|
202
204
|
- [`@immobiliarelabs/fastify-metrics`](https://github.com/immobiliare/fastify-metrics)
|
|
203
205
|
Minimalistic and opinionated plugin that collects usage/process metrics and
|
|
204
206
|
dispatches to [statsd](https://github.com/statsd/statsd).
|
|
@@ -507,6 +509,8 @@ middlewares into Fastify plugins
|
|
|
507
509
|
[MS Graph Change Notifications webhooks](https://learn.microsoft.com/it-it/graph/change-notifications-delivery-webhooks?tabs=http).
|
|
508
510
|
- [`fastify-multer`](https://github.com/fox1t/fastify-multer) Multer is a plugin
|
|
509
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.
|
|
510
514
|
- [`fastify-nats`](https://github.com/mahmed8003/fastify-nats) Plugin to share
|
|
511
515
|
[NATS](https://nats.io) client across Fastify.
|
|
512
516
|
- [`fastify-next-auth`](https://github.com/wobsoriano/fastify-next-auth)
|
|
@@ -557,6 +561,9 @@ middlewares into Fastify plugins
|
|
|
557
561
|
A set of Fastify plugins to integrate Apple Wallet Web Service specification
|
|
558
562
|
- [`fastify-peekaboo`](https://github.com/simone-sanfratello/fastify-peekaboo)
|
|
559
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.
|
|
560
567
|
- [`fastify-piscina`](https://github.com/piscinajs/fastify-piscina) A worker
|
|
561
568
|
thread pool plugin using [Piscina](https://github.com/piscinajs/piscina).
|
|
562
569
|
- [`fastify-polyglot`](https://github.com/beliven-it/fastify-polyglot) A plugin to
|
|
@@ -616,6 +623,9 @@ middlewares into Fastify plugins
|
|
|
616
623
|
Fastify Rob-Config integration.
|
|
617
624
|
- [`fastify-route-group`](https://github.com/TakNePoidet/fastify-route-group)
|
|
618
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.
|
|
619
629
|
- [`fastify-s3-buckets`](https://github.com/kibertoad/fastify-s3-buckets)
|
|
620
630
|
Ensure the existence of defined S3 buckets on the application startup.
|
|
621
631
|
- [`fastify-schema-constraint`](https://github.com/Eomm/fastify-schema-constraint)
|
|
@@ -734,6 +744,7 @@ middlewares into Fastify plugins
|
|
|
734
744
|
- [`typeorm-fastify-plugin`](https://github.com/jclemens24/fastify-typeorm) A simple
|
|
735
745
|
and updated Typeorm plugin for use with Fastify.
|
|
736
746
|
|
|
747
|
+
|
|
737
748
|
#### [Community Tools](#community-tools)
|
|
738
749
|
|
|
739
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,
|
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)
|
|
@@ -299,7 +300,8 @@ Below is a table with all the error codes used by Fastify.
|
|
|
299
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) |
|
|
300
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) |
|
|
301
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) |
|
|
302
|
-
| <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) |
|
|
303
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) |
|
|
304
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) |
|
|
305
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) |
|
package/docs/Reference/Hooks.md
CHANGED
|
@@ -189,12 +189,8 @@ 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.
|
|
@@ -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
|
```
|
|
@@ -237,7 +237,7 @@ const newValidate = request.compileValidationSchema(newSchema)
|
|
|
237
237
|
console.log(newValidate === validate) // false
|
|
238
238
|
```
|
|
239
239
|
|
|
240
|
-
### .validateInput(data, [schema |
|
|
240
|
+
### .validateInput(data, [schema | httpPart], [httpPart])
|
|
241
241
|
<a id="validate"></a>
|
|
242
242
|
|
|
243
243
|
This function validates the input based on the provided schema or HTTP part. If
|
package/docs/Reference/Routes.md
CHANGED
|
@@ -59,8 +59,9 @@ fastify.route(options)
|
|
|
59
59
|
one.
|
|
60
60
|
* `onRequest(request, reply, done)`: a [function](./Hooks.md#onrequest) called
|
|
61
61
|
as soon as a request is received, it could also be an array of functions.
|
|
62
|
-
* `preParsing(request, reply, done)`: a
|
|
63
|
-
before parsing the request, it could
|
|
62
|
+
* `preParsing(request, reply, payload, done)`: a
|
|
63
|
+
[function](./Hooks.md#preparsing) called before parsing the request, it could
|
|
64
|
+
also be an array of functions.
|
|
64
65
|
* `preValidation(request, reply, done)`: a [function](./Hooks.md#prevalidation)
|
|
65
66
|
called after the shared `preValidation` hooks, useful if you need to perform
|
|
66
67
|
authentication at route level for example, it could also be an array of
|
|
@@ -781,7 +782,7 @@ const secret = {
|
|
|
781
782
|
> const Fastify = require('fastify')
|
|
782
783
|
>
|
|
783
784
|
> const fastify = Fastify({
|
|
784
|
-
> frameworkErrors: function (err,
|
|
785
|
+
> frameworkErrors: function (err, req, res) {
|
|
785
786
|
> if (err instanceof Fastify.errorCodes.FST_ERR_ASYNC_CONSTRAINT) {
|
|
786
787
|
> res.code(400)
|
|
787
788
|
> return res.send("Invalid header provided")
|