fastify 5.0.0-alpha.2 → 5.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/SPONSORS.md +2 -0
- package/build/build-validation.js +3 -15
- package/docs/Guides/Ecosystem.md +4 -0
- package/docs/Guides/Getting-Started.md +0 -2
- package/docs/Guides/Migration-Guide-V4.md +48 -0
- package/docs/Guides/Recommendations.md +8 -6
- package/docs/Reference/Errors.md +0 -2
- package/docs/Reference/Hooks.md +5 -9
- package/docs/Reference/Logging.md +1 -1
- package/docs/Reference/Reply.md +9 -11
- package/docs/Reference/Request.md +0 -11
- package/docs/Reference/Routes.md +4 -23
- package/docs/Reference/Server.md +30 -40
- package/docs/Reference/Type-Providers.md +2 -2
- package/docs/Reference/TypeScript.md +16 -18
- package/docs/Reference/Validation-and-Serialization.md +62 -27
- package/docs/Reference/Warnings.md +0 -26
- package/eslint.config.js +9 -25
- package/fastify.d.ts +10 -23
- package/fastify.js +60 -61
- package/lib/configValidator.js +130 -182
- package/lib/context.js +1 -22
- package/lib/decorate.js +2 -2
- package/lib/errors.js +0 -6
- package/lib/handleRequest.js +5 -5
- package/lib/reply.js +34 -74
- package/lib/request.js +0 -45
- package/lib/route.js +12 -27
- package/lib/schemas.js +27 -22
- package/lib/server.js +6 -11
- package/lib/symbols.js +1 -1
- package/lib/validation.js +27 -6
- package/lib/warnings.js +1 -92
- package/lib/wrapThenable.js +1 -1
- package/package.json +14 -15
- package/test/decorator.test.js +1 -1
- package/test/diagnostics-channel/404.test.js +1 -1
- package/test/diagnostics-channel/async-delay-request.test.js +1 -1
- package/test/diagnostics-channel/async-request.test.js +1 -1
- package/test/diagnostics-channel/error-before-handler.test.js +1 -1
- package/test/diagnostics-channel/error-request.test.js +1 -1
- package/test/diagnostics-channel/error-status.test.js +1 -1
- package/test/diagnostics-channel/init.test.js +2 -2
- package/test/diagnostics-channel/sync-delay-request.test.js +1 -1
- package/test/diagnostics-channel/sync-request-reply.test.js +1 -1
- package/test/diagnostics-channel/sync-request.test.js +1 -1
- package/test/{copy.test.js → http-methods/copy.test.js} +2 -1
- package/test/http-methods/custom-http-methods.test.js +111 -0
- package/test/{get.test.js → http-methods/get.test.js} +1 -1
- package/test/{head.test.js → http-methods/head.test.js} +7 -87
- package/test/{lock.test.js → http-methods/lock.test.js} +2 -1
- package/test/{mkcalendar.test.js → http-methods/mkcalendar.test.js} +2 -1
- package/test/{mkcol.test.js → http-methods/mkcol.test.js} +2 -1
- package/test/{move.test.js → http-methods/move.test.js} +2 -1
- package/test/{propfind.test.js → http-methods/propfind.test.js} +2 -1
- package/test/{proppatch.test.js → http-methods/proppatch.test.js} +2 -1
- package/test/{report.test.js → http-methods/report.test.js} +2 -1
- package/test/{search.test.js → http-methods/search.test.js} +2 -1
- package/test/{trace.test.js → http-methods/trace.test.js} +2 -1
- package/test/{unlock.test.js → http-methods/unlock.test.js} +2 -1
- package/test/internals/all.test.js +3 -3
- package/test/internals/decorator.test.js +2 -2
- package/test/internals/errors.test.js +7 -17
- package/test/internals/initialConfig.test.js +0 -31
- package/test/internals/reply-serialize.test.js +25 -10
- package/test/internals/reply.test.js +31 -153
- package/test/internals/request-validate.test.js +21 -12
- package/test/internals/request.test.js +1 -18
- package/test/internals/validation.test.js +49 -56
- package/test/listen.1.test.js +66 -14
- package/test/listen.5.test.js +11 -0
- package/test/reply-trailers.test.js +1 -32
- package/test/route-shorthand.test.js +3 -1
- package/test/route.3.test.js +4 -1
- package/test/route.7.test.js +2 -12
- package/test/route.8.test.js +34 -5
- package/test/router-options.test.js +6 -3
- package/test/schema-examples.test.js +15 -6
- package/test/schema-feature.test.js +178 -35
- package/test/schema-serialization.test.js +125 -21
- package/test/schema-validation.test.js +154 -3
- package/test/skip-reply-send.test.js +6 -6
- package/test/stream-serializers.test.js +37 -0
- package/test/throw.test.js +2 -14
- package/test/types/errors.test-d.ts +1 -2
- package/test/types/fastify.test-d.ts +23 -34
- package/test/types/hooks.test-d.ts +56 -56
- package/test/types/instance.test-d.ts +3 -3
- package/test/types/reply.test-d.ts +7 -8
- package/test/types/request.test-d.ts +2 -12
- package/test/types/route.test-d.ts +158 -158
- package/test/types/schema.test-d.ts +22 -5
- package/test/versioned-routes.test.js +0 -90
- package/test/web-api.test.js +75 -0
- package/types/errors.d.ts +78 -79
- package/types/hooks.d.ts +18 -18
- package/types/instance.d.ts +1 -1
- package/types/logger.d.ts +7 -7
- package/types/reply.d.ts +18 -22
- package/types/request.d.ts +8 -14
- package/types/route.d.ts +5 -6
- package/types/type-provider.d.ts +1 -1
- package/.tap/processinfo/09002e93-10ad-430c-bc86-c0576928b0ed.json +0 -241
- package/.tap/processinfo/ee66c5ab-635d-48b5-8be6-3dc3ceea5bfc.json +0 -268
- package/.tap/test-results/test/404s.test.js.tap +0 -623
- package/.tap/test-results/test/500s.test.js.tap +0 -64
- package/.tap/test-results/test/allowUnsafeRegex.test.js.tap +0 -36
- package/.tap/test-results/test/als.test.js.tap +0 -15
- package/.tap/test-results/test/async-await.test.js.tap +0 -184
- package/.tap/test-results/test/async-dispose.test.js.tap +0 -8
- package/.tap/test-results/test/async_hooks.test.js.tap +0 -10
- package/.tap/test-results/test/bodyLimit.test.js.tap +0 -48
- package/.tap/test-results/test/buffer.test.js.tap +0 -20
- package/.tap/test-results/test/build/error-serializer.test.js.tap +0 -12
- package/.tap/test-results/test/build/version.test.js.tap +0 -7
- package/.tap/test-results/test/case-insensitive.test.js.tap +0 -36
- package/.tap/test-results/test/chainable.test.js.tap +0 -17
- package/.tap/test-results/test/check.test.js.tap +0 -10
- package/.tap/test-results/test/childLoggerFactory.test.js.tap +0 -23
- package/.tap/test-results/test/client-timeout.test.js.tap +0 -7
- package/.tap/test-results/test/close-pipelining.test.js.tap +0 -15
- package/.tap/test-results/test/close.test.js.tap +0 -172
- package/.tap/test-results/test/connectionTimeout.test.js.tap +0 -12
- package/.tap/test-results/test/constrained-routes.test.js.tap +0 -173
- package/.tap/test-results/test/content-length.test.js.tap +0 -46
- package/.tap/test-results/test/content-parser.test.js.tap +0 -266
- package/.tap/test-results/test/content-type.test.js.tap +0 -14
- package/.tap/test-results/test/context-config.test.js.tap +0 -41
- package/.tap/test-results/test/copy.test.js.tap +0 -14
- package/.tap/test-results/test/custom-http-server.test.js.tap +0 -30
- package/.tap/test-results/test/custom-parser-async.test.js.tap +0 -21
- package/.tap/test-results/test/custom-parser.0.test.js.tap +0 -199
- package/.tap/test-results/test/custom-parser.1.test.js.tap +0 -90
- package/.tap/test-results/test/custom-parser.2.test.js.tap +0 -22
- package/.tap/test-results/test/custom-parser.3.test.js.tap +0 -53
- package/.tap/test-results/test/custom-parser.4.test.js.tap +0 -45
- package/.tap/test-results/test/custom-parser.5.test.js.tap +0 -41
- package/.tap/test-results/test/custom-querystring-parser.test.js.tap +0 -46
- package/.tap/test-results/test/decorator.test.js.tap +0 -465
- package/.tap/test-results/test/delete.test.js.tap +0 -110
- package/.tap/test-results/test/diagnostics-channel/404.test.js.tap +0 -15
- package/.tap/test-results/test/diagnostics-channel/async-delay-request.test.js.tap +0 -25
- package/.tap/test-results/test/diagnostics-channel/async-request.test.js.tap +0 -24
- package/.tap/test-results/test/diagnostics-channel/error-before-handler.test.js.tap +0 -9
- package/.tap/test-results/test/diagnostics-channel/error-request.test.js.tap +0 -20
- package/.tap/test-results/test/diagnostics-channel/error-status.test.js.tap +0 -10
- package/.tap/test-results/test/diagnostics-channel/init.test.js.tap +0 -14
- package/.tap/test-results/test/diagnostics-channel/sync-delay-request.test.js.tap +0 -16
- package/.tap/test-results/test/diagnostics-channel/sync-request-reply.test.js.tap +0 -16
- package/.tap/test-results/test/diagnostics-channel/sync-request.test.js.tap +0 -19
- package/.tap/test-results/test/encapsulated-child-logger-factory.test.js.tap +0 -18
- package/.tap/test-results/test/encapsulated-error-handler.test.js.tap +0 -243
- package/.tap/test-results/test/esm/errorCodes.test.mjs.tap +0 -9
- package/.tap/test-results/test/esm/esm.test.mjs.tap +0 -8
- package/.tap/test-results/test/esm/index.test.js.tap +0 -8
- package/.tap/test-results/test/fastify-instance.test.js.tap +0 -114
- package/.tap/test-results/test/findRoute.test.js.tap +0 -37
- package/.tap/test-results/test/fluent-schema.test.js.tap +0 -36
- package/.tap/test-results/test/genReqId.test.js.tap +0 -106
- package/.tap/test-results/test/get.test.js.tap +0 -151
- package/.tap/test-results/test/handler-context.test.js.tap +0 -19
- package/.tap/test-results/test/has-route.test.js.tap +0 -30
- package/.tap/test-results/test/head.test.js.tap +0 -130
- package/.tap/test-results/test/header-overflow.test.js.tap +0 -16
- package/.tap/test-results/test/hooks-async.test.js.tap +0 -286
- package/.tap/test-results/test/hooks.on-listen.test.js.tap +0 -311
- package/.tap/test-results/test/hooks.on-ready.test.js.tap +0 -151
- package/.tap/test-results/test/hooks.test.js.tap +0 -966
- package/.tap/test-results/test/http2/closing.test.js.tap +0 -35
- package/.tap/test-results/test/http2/constraint.test.js.tap +0 -32
- package/.tap/test-results/test/http2/head.test.js.tap +0 -9
- package/.tap/test-results/test/http2/missing-http2-module.test.js.tap +0 -8
- package/.tap/test-results/test/http2/plain.test.js.tap +0 -22
- package/.tap/test-results/test/http2/secure-with-fallback.test.js.tap +0 -40
- package/.tap/test-results/test/http2/secure.test.js.tap +0 -27
- package/.tap/test-results/test/http2/unknown-http-method.test.js.tap +0 -9
- package/.tap/test-results/test/https/custom-https-server.test.js.tap +0 -10
- package/.tap/test-results/test/https/https.test.js.tap +0 -45
- package/.tap/test-results/test/imports.test.js.tap +0 -14
- package/.tap/test-results/test/inject.test.js.tap +0 -165
- package/.tap/test-results/test/internals/all.test.js.tap +0 -42
- package/.tap/test-results/test/internals/contentTypeParser.test.js.tap +0 -14
- package/.tap/test-results/test/internals/context.test.js.tap +0 -14
- package/.tap/test-results/test/internals/decorator.test.js.tap +0 -51
- package/.tap/test-results/test/internals/errors.test.js.tap +0 -1212
- package/.tap/test-results/test/internals/handleRequest.test.js.tap +0 -69
- package/.tap/test-results/test/internals/hookRunner.test.js.tap +0 -143
- package/.tap/test-results/test/internals/hooks.test.js.tap +0 -45
- package/.tap/test-results/test/internals/initialConfig.test.js.tap +0 -125
- package/.tap/test-results/test/internals/logger.test.js.tap +0 -71
- package/.tap/test-results/test/internals/plugin.test.js.tap +0 -48
- package/.tap/test-results/test/internals/reply-serialize.test.js.tap +0 -166
- package/.tap/test-results/test/internals/reply.test.js.tap +0 -688
- package/.tap/test-results/test/internals/reqIdGenFactory.test.js.tap +0 -74
- package/.tap/test-results/test/internals/request-validate.test.js.tap +0 -384
- package/.tap/test-results/test/internals/request.test.js.tap +0 -163
- package/.tap/test-results/test/internals/server.test.js.tap +0 -30
- package/.tap/test-results/test/internals/validation.test.js.tap +0 -121
- package/.tap/test-results/test/keepAliveTimeout.test.js.tap +0 -12
- package/.tap/test-results/test/listen.1.test.js.tap +0 -31
- package/.tap/test-results/test/listen.2.test.js.tap +0 -46
- package/.tap/test-results/test/listen.3.test.js.tap +0 -25
- package/.tap/test-results/test/listen.4.test.js.tap +0 -51
- package/.tap/test-results/test/lock.test.js.tap +0 -29
- package/.tap/test-results/test/logger/instantiation.test.js.tap +0 -92
- package/.tap/test-results/test/logger/logging.test.js.tap +0 -117
- package/.tap/test-results/test/logger/options.test.js.tap +0 -165
- package/.tap/test-results/test/logger/request.test.js.tap +0 -82
- package/.tap/test-results/test/logger/response.test.js.tap +0 -38
- package/.tap/test-results/test/maxRequestsPerSocket.test.js.tap +0 -44
- package/.tap/test-results/test/method-missing.test.js.tap +0 -8
- package/.tap/test-results/test/middleware.test.js.tap +0 -17
- package/.tap/test-results/test/mkcalendar.test.js.tap +0 -43
- package/.tap/test-results/test/mkcol.test.js.tap +0 -14
- package/.tap/test-results/test/move.test.js.tap +0 -15
- package/.tap/test-results/test/noop-set.test.js.tap +0 -8
- package/.tap/test-results/test/nullable-validation.test.js.tap +0 -36
- package/.tap/test-results/test/options.error-handler.test.js.tap +0 -186
- package/.tap/test-results/test/options.test.js.tap +0 -174
- package/.tap/test-results/test/output-validation.test.js.tap +0 -66
- package/.tap/test-results/test/patch.error-handler.test.js.tap +0 -206
- package/.tap/test-results/test/patch.test.js.tap +0 -182
- package/.tap/test-results/test/plugin.1.test.js.tap +0 -78
- package/.tap/test-results/test/plugin.2.test.js.tap +0 -102
- package/.tap/test-results/test/plugin.3.test.js.tap +0 -58
- package/.tap/test-results/test/plugin.4.test.js.tap +0 -164
- package/.tap/test-results/test/post-empty-body.test.js.tap +0 -8
- package/.tap/test-results/test/pretty-print.test.js.tap +0 -82
- package/.tap/test-results/test/promises.test.js.tap +0 -46
- package/.tap/test-results/test/propfind.test.js.tap +0 -43
- package/.tap/test-results/test/proppatch.test.js.tap +0 -29
- package/.tap/test-results/test/proto-poisoning.test.js.tap +0 -47
- package/.tap/test-results/test/put.error-handler.test.js.tap +0 -206
- package/.tap/test-results/test/put.test.js.tap +0 -182
- package/.tap/test-results/test/register.test.js.tap +0 -61
- package/.tap/test-results/test/reply-code.test.js.tap +0 -40
- package/.tap/test-results/test/reply-earlyHints.test.js.tap +0 -22
- package/.tap/test-results/test/reply-error.test.js.tap +0 -643
- package/.tap/test-results/test/reply-trailers.test.js.tap +0 -176
- package/.tap/test-results/test/report.test.js.tap +0 -43
- package/.tap/test-results/test/request-error.test.js.tap +0 -98
- package/.tap/test-results/test/request-id.test.js.tap +0 -38
- package/.tap/test-results/test/request.deprecated.test.js.tap +0 -13
- package/.tap/test-results/test/requestTimeout.test.js.tap +0 -21
- package/.tap/test-results/test/route-hooks.test.js.tap +0 -498
- package/.tap/test-results/test/route-prefix.test.js.tap +0 -195
- package/.tap/test-results/test/route-shorthand.test.js.tap +0 -190
- package/.tap/test-results/test/route.1.test.js.tap +0 -93
- package/.tap/test-results/test/route.2.test.js.tap +0 -28
- package/.tap/test-results/test/route.3.test.js.tap +0 -39
- package/.tap/test-results/test/route.4.test.js.tap +0 -32
- package/.tap/test-results/test/route.5.test.js.tap +0 -54
- package/.tap/test-results/test/route.6.test.js.tap +0 -81
- package/.tap/test-results/test/route.7.test.js.tap +0 -93
- package/.tap/test-results/test/route.8.test.js.tap +0 -38
- package/.tap/test-results/test/router-options.test.js.tap +0 -104
- package/.tap/test-results/test/same-shape.test.js.tap +0 -22
- package/.tap/test-results/test/schema-examples.test.js.tap +0 -85
- package/.tap/test-results/test/schema-feature.test.js.tap +0 -445
- package/.tap/test-results/test/schema-serialization.test.js.tap +0 -194
- package/.tap/test-results/test/schema-special-usage.test.js.tap +0 -186
- package/.tap/test-results/test/schema-validation.test.js.tap +0 -199
- package/.tap/test-results/test/search.test.js.tap +0 -77
- package/.tap/test-results/test/serialize-response.test.js.tap +0 -26
- package/.tap/test-results/test/server.test.js.tap +0 -65
- package/.tap/test-results/test/set-error-handler.test.js.tap +0 -7
- package/.tap/test-results/test/skip-reply-send.test.js.tap +0 -272
- package/.tap/test-results/test/stream.1.test.js.tap +0 -36
- package/.tap/test-results/test/stream.2.test.js.tap +0 -20
- package/.tap/test-results/test/stream.3.test.js.tap +0 -34
- package/.tap/test-results/test/stream.4.test.js.tap +0 -40
- package/.tap/test-results/test/stream.5.test.js.tap +0 -37
- package/.tap/test-results/test/sync-routes.test.js.tap +0 -19
- package/.tap/test-results/test/throw.test.js.tap +0 -116
- package/.tap/test-results/test/trace.test.js.tap +0 -7
- package/.tap/test-results/test/trust-proxy.test.js.tap +0 -109
- package/.tap/test-results/test/type-provider.test.js.tap +0 -12
- package/.tap/test-results/test/unlock.test.js.tap +0 -14
- package/.tap/test-results/test/upgrade.test.js.tap +0 -8
- package/.tap/test-results/test/url-rewriting.test.js.tap +0 -39
- package/.tap/test-results/test/useSemicolonDelimiter.test.js.tap +0 -33
- package/.tap/test-results/test/validation-error-handling.test.js.tap +0 -180
- package/.tap/test-results/test/versioned-routes.test.js.tap +0 -151
- package/.tap/test-results/test/web-api.test.js.tap +0 -51
- package/.tap/test-results/test/wrapThenable.test.js.tap +0 -11
- package/EXPENSE_POLICY.md +0 -105
- package/lib/httpMethods.js +0 -40
- package/test/method-missing.test.js +0 -24
- package/test/request.deprecated.test.js +0 -38
package/README.md
CHANGED
|
@@ -307,8 +307,6 @@ listed in alphabetical order.
|
|
|
307
307
|
<https://twitter.com/serayaeryn>, <https://www.npmjs.com/~serayaeryn>
|
|
308
308
|
* [__Carlos Fuentes__](https://github.com/metcoder95),
|
|
309
309
|
<https://twitter.com/metcoder95>, <https://www.npmjs.com/~metcoder95>
|
|
310
|
-
* [__Rafael Gonzaga__](https://github.com/rafaelgss),
|
|
311
|
-
<https://twitter.com/_rafaelgss>, <https://www.npmjs.com/~rafaelgss>
|
|
312
310
|
* [__Vincent Le Goff__](https://github.com/zekth)
|
|
313
311
|
* [__Luciano Mammino__](https://github.com/lmammino),
|
|
314
312
|
<https://twitter.com/loige>, <https://www.npmjs.com/~lmammino>
|
|
@@ -371,6 +369,8 @@ to join this group by Lead Maintainers.
|
|
|
371
369
|
<https://twitter.com/NathanWoltman>, <https://www.npmjs.com/~nwoltman>
|
|
372
370
|
* [__Ethan Arrowood__](https://github.com/Ethan-Arrowood/),
|
|
373
371
|
<https://twitter.com/arrowoodtech>, <https://www.npmjs.com/~ethan_arrowood>
|
|
372
|
+
* [__Rafael Gonzaga__](https://github.com/rafaelgss),
|
|
373
|
+
<https://twitter.com/_rafaelgss>, <https://www.npmjs.com/~rafaelgss>
|
|
374
374
|
|
|
375
375
|
## Hosted by
|
|
376
376
|
|
package/SPONSORS.md
CHANGED
|
@@ -14,6 +14,8 @@ _Be the first!_
|
|
|
14
14
|
## Tier 3
|
|
15
15
|
|
|
16
16
|
- [Mercedes-Benz Group](https://github.com/mercedes-benz)
|
|
17
|
+
- [Val Town, Inc.](https://opencollective.com/valtown)
|
|
18
|
+
- [Handsontable - JavaScript Data Grid](https://handsontable.com/docs/react-data-grid/?utm_source=Fastify_GH&utm_medium=sponsorship&utm_campaign=library_sponsorship_2024)
|
|
17
19
|
|
|
18
20
|
## Tier 2
|
|
19
21
|
|
|
@@ -32,7 +32,6 @@ const defaultInitOptions = {
|
|
|
32
32
|
caseSensitive: true,
|
|
33
33
|
allowUnsafeRegex: false,
|
|
34
34
|
disableRequestLogging: false,
|
|
35
|
-
jsonShorthand: true,
|
|
36
35
|
ignoreTrailingSlash: false,
|
|
37
36
|
ignoreDuplicateSlashes: false,
|
|
38
37
|
maxParamLength: 100,
|
|
@@ -94,7 +93,6 @@ const schema = {
|
|
|
94
93
|
type: 'boolean',
|
|
95
94
|
default: false
|
|
96
95
|
},
|
|
97
|
-
jsonShorthand: { type: 'boolean', default: defaultInitOptions.jsonShorthand },
|
|
98
96
|
maxParamLength: { type: 'integer', default: defaultInitOptions.maxParamLength },
|
|
99
97
|
onProtoPoisoning: { type: 'string', default: defaultInitOptions.onProtoPoisoning },
|
|
100
98
|
onConstructorPoisoning: { type: 'string', default: defaultInitOptions.onConstructorPoisoning },
|
|
@@ -104,16 +102,6 @@ const schema = {
|
|
|
104
102
|
http2SessionTimeout: { type: 'integer', default: defaultInitOptions.http2SessionTimeout },
|
|
105
103
|
exposeHeadRoutes: { type: 'boolean', default: defaultInitOptions.exposeHeadRoutes },
|
|
106
104
|
useSemicolonDelimiter: { type: 'boolean', default: defaultInitOptions.useSemicolonDelimiter },
|
|
107
|
-
// deprecated style of passing the versioning constraint
|
|
108
|
-
versioning: {
|
|
109
|
-
type: 'object',
|
|
110
|
-
additionalProperties: true,
|
|
111
|
-
required: ['storage', 'deriveVersion'],
|
|
112
|
-
properties: {
|
|
113
|
-
storage: { },
|
|
114
|
-
deriveVersion: { }
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
105
|
constraints: {
|
|
118
106
|
type: 'object',
|
|
119
107
|
additionalProperties: {
|
|
@@ -122,9 +110,9 @@ const schema = {
|
|
|
122
110
|
additionalProperties: true,
|
|
123
111
|
properties: {
|
|
124
112
|
name: { type: 'string' },
|
|
125
|
-
storage: {
|
|
126
|
-
validate: {
|
|
127
|
-
deriveConstraint: {
|
|
113
|
+
storage: {},
|
|
114
|
+
validate: {},
|
|
115
|
+
deriveConstraint: {}
|
|
128
116
|
}
|
|
129
117
|
}
|
|
130
118
|
}
|
package/docs/Guides/Ecosystem.md
CHANGED
|
@@ -159,6 +159,8 @@ section.
|
|
|
159
159
|
|
|
160
160
|
#### [Community](#community)
|
|
161
161
|
|
|
162
|
+
- [`@aaroncadillac/crudify-mongo`](https://github.com/aaroncadillac/crudify-mongo)
|
|
163
|
+
A simple way to add a crud in your fastify project.
|
|
162
164
|
- [`@applicazza/fastify-nextjs`](https://github.com/applicazza/fastify-nextjs)
|
|
163
165
|
Alternate Fastify and Next.js integration.
|
|
164
166
|
- [`@blastorg/fastify-aws-dynamodb-cache`](https://github.com/blastorg/fastify-aws-dynamodb-cache)
|
|
@@ -213,6 +215,8 @@ section.
|
|
|
213
215
|
Fast sodium-based crypto for @mgcrea/fastify-session
|
|
214
216
|
- [`@mgcrea/pino-pretty-compact`](https://github.com/mgcrea/pino-pretty-compact)
|
|
215
217
|
A custom compact pino-base prettifier
|
|
218
|
+
- [`@pybot/fastify-autoload`](https://github.com/kunal097/fastify-autoload)
|
|
219
|
+
Plugin to generate routes automatically with valid json content
|
|
216
220
|
- [`@scalar/fastify-api-reference`](https://github.com/scalar/scalar/tree/main/packages/fastify-api-reference)
|
|
217
221
|
Beautiful OpenAPI/Swagger API references for Fastify
|
|
218
222
|
- [`@trubavuong/fastify-seaweedfs`](https://github.com/trubavuong/fastify-seaweedfs)
|
|
@@ -450,8 +450,6 @@ Data validation is extremely important and a core concept of the framework.
|
|
|
450
450
|
To validate incoming requests, Fastify uses [JSON
|
|
451
451
|
Schema](https://json-schema.org/).
|
|
452
452
|
|
|
453
|
-
(JTD schemas are loosely supported, but `jsonShorthand` must be disabled first)
|
|
454
|
-
|
|
455
453
|
Let's look at an example demonstrating validation for routes:
|
|
456
454
|
```js
|
|
457
455
|
/**
|
|
@@ -6,6 +6,30 @@ Before migrating to v4, please ensure that you have fixed all deprecation
|
|
|
6
6
|
warnings from v3. All v3 deprecations have been removed and they will no longer
|
|
7
7
|
work after upgrading.
|
|
8
8
|
|
|
9
|
+
## Codemods
|
|
10
|
+
### Fastify v4 Codemods
|
|
11
|
+
|
|
12
|
+
To help with the upgrade, we’ve worked with the team at codemod.com to
|
|
13
|
+
publish codemods that will automatically update your code to many of
|
|
14
|
+
the new APIs and patterns in Fastify v4.
|
|
15
|
+
Run the following codemods to automatically update your code for Fastify v4 migration:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
npx codemod@latest fastify/4/migration-recipe
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This will run the following codemods from the Fastify Codemod repository:
|
|
22
|
+
|
|
23
|
+
- **fastify/4/remove-app-use**
|
|
24
|
+
- **fastify/4/reply-raw-access**
|
|
25
|
+
- **fastify/4/wrap-routes-plugin**
|
|
26
|
+
- **fastify/4/await-register-calls**
|
|
27
|
+
|
|
28
|
+
Each of these codemods automates the changes listed in the v4 migration guide.
|
|
29
|
+
For a complete list of available Fastify codemods and further details,
|
|
30
|
+
see the [codemod registry](https://codemod.com/registry?q=fastify).
|
|
31
|
+
|
|
32
|
+
|
|
9
33
|
## Breaking Changes
|
|
10
34
|
|
|
11
35
|
### Error handling composition ([#3261](https://github.com/fastify/fastify/pull/3261))
|
|
@@ -55,11 +79,23 @@ If you need to use middleware, use
|
|
|
55
79
|
continue to be maintained.
|
|
56
80
|
However, it is strongly recommended that you migrate to Fastify's [hooks](../Reference/Hooks.md).
|
|
57
81
|
|
|
82
|
+
> **Note**: Codemod remove `app.use()` with:
|
|
83
|
+
>
|
|
84
|
+
> ```bash
|
|
85
|
+
> npx codemod@latest fastify/4/remove-app-use
|
|
86
|
+
> ```
|
|
87
|
+
|
|
58
88
|
### `reply.res` moved to `reply.raw`
|
|
59
89
|
|
|
60
90
|
If you previously used the `reply.res` attribute to access the underlying Request
|
|
61
91
|
object you will now need to use `reply.raw`.
|
|
62
92
|
|
|
93
|
+
> **Note**: Codemod `reply.res` to `reply.raw` with:
|
|
94
|
+
>
|
|
95
|
+
> ```bash
|
|
96
|
+
> npx codemod@latest fastify/4/reply-raw-access
|
|
97
|
+
> ```
|
|
98
|
+
|
|
63
99
|
### Need to `return reply` to signal a "fork" of the promise chain
|
|
64
100
|
|
|
65
101
|
In some situations, like when a response is sent asynchronously or when you are
|
|
@@ -105,6 +141,11 @@ As a result, if you specify an `onRoute` hook in a plugin you should now either:
|
|
|
105
141
|
done();
|
|
106
142
|
});
|
|
107
143
|
```
|
|
144
|
+
> **Note**: Codemod synchronous route definitions with:
|
|
145
|
+
>
|
|
146
|
+
> ```bash
|
|
147
|
+
> npx codemod@latest fastify/4/wrap-routes-plugin
|
|
148
|
+
> ```
|
|
108
149
|
|
|
109
150
|
* use `await register(...)`
|
|
110
151
|
|
|
@@ -130,6 +171,13 @@ As a result, if you specify an `onRoute` hook in a plugin you should now either:
|
|
|
130
171
|
});
|
|
131
172
|
```
|
|
132
173
|
|
|
174
|
+
> **Note**: Codemod 'await register(...)' with:
|
|
175
|
+
>
|
|
176
|
+
> ```bash
|
|
177
|
+
> npx codemod@latest fastify/4/await-register-calls
|
|
178
|
+
> ```
|
|
179
|
+
|
|
180
|
+
|
|
133
181
|
### Optional URL parameters
|
|
134
182
|
|
|
135
183
|
If you've already used any implicitly optional parameters, you'll get a 404
|
|
@@ -212,17 +212,19 @@ server {
|
|
|
212
212
|
# server group via port 3000.
|
|
213
213
|
server {
|
|
214
214
|
# This listen directive asks NGINX to accept requests
|
|
215
|
-
# coming to any address, port 443, with SSL
|
|
216
|
-
|
|
217
|
-
listen 443 ssl
|
|
218
|
-
listen [::]:443 ssl http2 default_server;
|
|
215
|
+
# coming to any address, port 443, with SSL.
|
|
216
|
+
listen 443 ssl default_server;
|
|
217
|
+
listen [::]:443 ssl default_server;
|
|
219
218
|
|
|
220
219
|
# With a server_name directive you can also ask NGINX to
|
|
221
220
|
# use this server block only with matching server name(s)
|
|
222
|
-
# listen 443 ssl
|
|
223
|
-
# listen [::]:443 ssl
|
|
221
|
+
# listen 443 ssl;
|
|
222
|
+
# listen [::]:443 ssl;
|
|
224
223
|
# server_name example.tld;
|
|
225
224
|
|
|
225
|
+
# Enable HTTP/2 support
|
|
226
|
+
http2 on;
|
|
227
|
+
|
|
226
228
|
# Your SSL/TLS certificate (chain) and secret key in the PEM format
|
|
227
229
|
ssl_certificate /path/to/fullchain.pem;
|
|
228
230
|
ssl_certificate_key /path/to/private.pem;
|
package/docs/Reference/Errors.md
CHANGED
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
- [FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN](#fst_err_schema_error_formatter_not_fn)
|
|
21
21
|
- [FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ](#fst_err_ajv_custom_options_opt_not_obj)
|
|
22
22
|
- [FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR](#fst_err_ajv_custom_options_opt_not_arr)
|
|
23
|
-
- [FST_ERR_VERSION_CONSTRAINT_NOT_STR](#fst_err_version_constraint_not_str)
|
|
24
23
|
- [FST_ERR_CTP_ALREADY_PRESENT](#fst_err_ctp_already_present)
|
|
25
24
|
- [FST_ERR_CTP_INVALID_TYPE](#fst_err_ctp_invalid_type)
|
|
26
25
|
- [FST_ERR_CTP_EMPTY_TYPE](#fst_err_ctp_empty_type)
|
|
@@ -293,7 +292,6 @@ Below is a table with all the error codes that Fastify uses.
|
|
|
293
292
|
| <a id="fst_err_schema_error_formatter_not_fn">FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN</a> | SchemaErrorFormatter option wrongly specified. | SchemaErrorFormatter option should be a non async function. | [#4554](https://github.com/fastify/fastify/pull/4554) |
|
|
294
293
|
| <a id="fst_err_ajv_custom_options_opt_not_obj">FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ</a> | ajv.customOptions wrongly specified. | ajv.customOptions option should be an object. | [#4554](https://github.com/fastify/fastify/pull/4554) |
|
|
295
294
|
| <a id="fst_err_ajv_custom_options_opt_not_arr">FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR</a> | ajv.plugins option wrongly specified. | ajv.plugins option should be an array. | [#4554](https://github.com/fastify/fastify/pull/4554) |
|
|
296
|
-
| <a id="fst_err_version_constraint_not_str">FST_ERR_VERSION_CONSTRAINT_NOT_STR</a> | Version constraint wrongly specified. | Version constraint should be a string. | [#4554](https://github.com/fastify/fastify/pull/4554) |
|
|
297
295
|
| <a id="fst_err_ctp_already_present">FST_ERR_CTP_ALREADY_PRESENT</a> | The parser for this content type was already registered. | Use a different content type or delete the already registered parser. | [#1168](https://github.com/fastify/fastify/pull/1168) |
|
|
298
296
|
| <a id="fst_err_ctp_invalid_type">FST_ERR_CTP_INVALID_TYPE</a> | `Content-Type` wrongly specified | The `Content-Type` should be a string. | [#1168](https://github.com/fastify/fastify/pull/1168) |
|
|
299
297
|
| <a id="fst_err_ctp_empty_type">FST_ERR_CTP_EMPTY_TYPE</a> | `Content-Type` is an empty string. | `Content-Type` cannot be an empty string. | [#1168](https://github.com/fastify/fastify/pull/1168) |
|
package/docs/Reference/Hooks.md
CHANGED
|
@@ -828,13 +828,6 @@ consider creating a custom [Plugin](./Plugins.md) instead.
|
|
|
828
828
|
|
|
829
829
|
## Diagnostics Channel Hooks
|
|
830
830
|
|
|
831
|
-
> **Note:** The `diagnostics_channel` is currently experimental on Node.js, so
|
|
832
|
-
> its API is subject to change even in semver-patch releases of Node.js. As some
|
|
833
|
-
> versions of Node.js are supported by Fastify where `diagnostics_channel` is
|
|
834
|
-
> unavailable, or with an incomplete feature set, the hook uses the
|
|
835
|
-
> [dc-polyfill](https://www.npmjs.com/package/dc-polyfill) package to provide a
|
|
836
|
-
> polyfill.
|
|
837
|
-
|
|
838
831
|
One [`diagnostics_channel`](https://nodejs.org/api/diagnostics_channel.html)
|
|
839
832
|
publish event, `'fastify.initialization'`, happens at initialization time. The
|
|
840
833
|
Fastify instance is passed into the hook as a property of the object passed in.
|
|
@@ -848,7 +841,7 @@ tools first" fashion.
|
|
|
848
841
|
|
|
849
842
|
```js
|
|
850
843
|
const tracer = /* retrieved from elsewhere in the package */
|
|
851
|
-
const dc = require('node:diagnostics_channel')
|
|
844
|
+
const dc = require('node:diagnostics_channel')
|
|
852
845
|
const channel = dc.channel('fastify.initialization')
|
|
853
846
|
const spans = new WeakMap()
|
|
854
847
|
|
|
@@ -867,6 +860,9 @@ channel.subscribe(function ({ fastify }) {
|
|
|
867
860
|
})
|
|
868
861
|
```
|
|
869
862
|
|
|
863
|
+
> **Note:** The TracingChannel class API is currently experimental and may undergo
|
|
864
|
+
> breaking changes even in semver-patch releases of Node.js.
|
|
865
|
+
|
|
870
866
|
Five other events are published on a per-request basis following the
|
|
871
867
|
[Tracing Channel](https://nodejs.org/api/diagnostics_channel.html#class-tracingchannel)
|
|
872
868
|
nomenclature. The list of the channel names and the event they receive is:
|
|
@@ -895,7 +891,7 @@ associated with the request's failure.
|
|
|
895
891
|
These events can be received like so:
|
|
896
892
|
|
|
897
893
|
```js
|
|
898
|
-
const dc = require('node:diagnostics_channel')
|
|
894
|
+
const dc = require('node:diagnostics_channel')
|
|
899
895
|
const channel = dc.channel('tracing:fastify.request.handler:start')
|
|
900
896
|
channel.subscribe((msg) => {
|
|
901
897
|
console.log(msg.request, msg.reply)
|
|
@@ -140,7 +140,7 @@ const fastify = require('fastify')({
|
|
|
140
140
|
return {
|
|
141
141
|
method: request.method,
|
|
142
142
|
url: request.url,
|
|
143
|
-
path: request.
|
|
143
|
+
path: request.routeOptions.url,
|
|
144
144
|
parameters: request.params,
|
|
145
145
|
// Including the headers in the log could be in violation
|
|
146
146
|
// of privacy laws, e.g. GDPR. You should use the "redact" option to
|
package/docs/Reference/Reply.md
CHANGED
|
@@ -92,7 +92,6 @@ since the request was received by Fastify.
|
|
|
92
92
|
from Node core.
|
|
93
93
|
- `.log` - The logger instance of the incoming request.
|
|
94
94
|
- `.request` - The incoming request.
|
|
95
|
-
- `.context` - Deprecated, access the [Request's context](./Request.md) property.
|
|
96
95
|
|
|
97
96
|
```js
|
|
98
97
|
fastify.get('/', options, function (request, reply) {
|
|
@@ -104,14 +103,6 @@ fastify.get('/', options, function (request, reply) {
|
|
|
104
103
|
})
|
|
105
104
|
```
|
|
106
105
|
|
|
107
|
-
Additionally, `Reply` provides access to the context of the request:
|
|
108
|
-
|
|
109
|
-
```js
|
|
110
|
-
fastify.get('/', {config: {foo: 'bar'}}, function (request, reply) {
|
|
111
|
-
reply.send('handler config.foo = ' + reply.context.config.foo)
|
|
112
|
-
})
|
|
113
|
-
```
|
|
114
|
-
|
|
115
106
|
### .code(statusCode)
|
|
116
107
|
<a id="code"></a>
|
|
117
108
|
|
|
@@ -700,8 +691,9 @@ As noted above, streams are considered to be pre-serialized, so they will be
|
|
|
700
691
|
sent unmodified without response validation.
|
|
701
692
|
|
|
702
693
|
```js
|
|
694
|
+
const fs = require('node:fs')
|
|
695
|
+
|
|
703
696
|
fastify.get('/streams', function (request, reply) {
|
|
704
|
-
const fs = require('node:fs')
|
|
705
697
|
const stream = fs.createReadStream('some-file', 'utf8')
|
|
706
698
|
reply.header('Content-Type', 'application/octet-stream')
|
|
707
699
|
reply.send(stream)
|
|
@@ -709,8 +701,9 @@ fastify.get('/streams', function (request, reply) {
|
|
|
709
701
|
```
|
|
710
702
|
When using async-await you will need to return or await the reply object:
|
|
711
703
|
```js
|
|
704
|
+
const fs = require('node:fs')
|
|
705
|
+
|
|
712
706
|
fastify.get('/streams', async function (request, reply) {
|
|
713
|
-
const fs = require('node:fs')
|
|
714
707
|
const stream = fs.createReadStream('some-file', 'utf8')
|
|
715
708
|
reply.header('Content-Type', 'application/octet-stream')
|
|
716
709
|
return reply.send(stream)
|
|
@@ -728,6 +721,7 @@ sent unmodified without response validation.
|
|
|
728
721
|
|
|
729
722
|
```js
|
|
730
723
|
const fs = require('node:fs')
|
|
724
|
+
|
|
731
725
|
fastify.get('/streams', function (request, reply) {
|
|
732
726
|
fs.readFile('some-file', (err, fileBuffer) => {
|
|
733
727
|
reply.send(err || fileBuffer)
|
|
@@ -738,6 +732,7 @@ fastify.get('/streams', function (request, reply) {
|
|
|
738
732
|
When using async-await you will need to return or await the reply object:
|
|
739
733
|
```js
|
|
740
734
|
const fs = require('node:fs')
|
|
735
|
+
|
|
741
736
|
fastify.get('/streams', async function (request, reply) {
|
|
742
737
|
fs.readFile('some-file', (err, fileBuffer) => {
|
|
743
738
|
reply.send(err || fileBuffer)
|
|
@@ -757,6 +752,7 @@ will be sent unmodified without response validation.
|
|
|
757
752
|
|
|
758
753
|
```js
|
|
759
754
|
const fs = require('node:fs')
|
|
755
|
+
|
|
760
756
|
fastify.get('/streams', function (request, reply) {
|
|
761
757
|
const typedArray = new Uint16Array(10)
|
|
762
758
|
reply.send(typedArray)
|
|
@@ -773,6 +769,7 @@ sent unmodified without response validation.
|
|
|
773
769
|
```js
|
|
774
770
|
const fs = require('node:fs')
|
|
775
771
|
const { ReadableStream } = require('node:stream/web')
|
|
772
|
+
|
|
776
773
|
fastify.get('/streams', function (request, reply) {
|
|
777
774
|
const stream = fs.createReadStream('some-file')
|
|
778
775
|
reply.header('Content-Type', 'application/octet-stream')
|
|
@@ -797,6 +794,7 @@ and may confuse when checking the `payload` in `onSend` hooks.
|
|
|
797
794
|
```js
|
|
798
795
|
const fs = require('node:fs')
|
|
799
796
|
const { ReadableStream } = require('node:stream/web')
|
|
797
|
+
|
|
800
798
|
fastify.get('/streams', function (request, reply) {
|
|
801
799
|
const stream = fs.createReadStream('some-file')
|
|
802
800
|
const readableStream = ReadableStream.from(stream)
|
|
@@ -31,23 +31,12 @@ Request is a core Fastify object containing the following fields:
|
|
|
31
31
|
- `url` - the URL of the incoming request
|
|
32
32
|
- `originalUrl` - similar to `url`, this allows you to access the
|
|
33
33
|
original `url` in case of internal re-routing
|
|
34
|
-
- `routerMethod` - Deprecated, use `request.routeOptions.method` instead. The
|
|
35
|
-
method defined for the router that is handling the request
|
|
36
|
-
- `routerPath` - Deprecated, use `request.routeOptions.url` instead. The
|
|
37
|
-
path pattern defined for the router that is handling the request
|
|
38
34
|
- `is404` - true if request is being handled by 404 handler, false if it is not
|
|
39
|
-
- `connection` - Deprecated, use `socket` instead. The underlying connection of
|
|
40
|
-
the incoming request.
|
|
41
35
|
- `socket` - the underlying connection of the incoming request
|
|
42
36
|
- `context` - Deprecated, use `request.routeOptions.config` instead.
|
|
43
37
|
A Fastify internal object. You should not use
|
|
44
38
|
it directly or modify it. It is useful to access one special key:
|
|
45
39
|
- `context.config` - The route [`config`](./Routes.md#routes-config) object.
|
|
46
|
-
- `routeSchema` - Deprecated, use `request.routeOptions.schema` instead. The
|
|
47
|
-
scheme definition set for the router that is handling the request
|
|
48
|
-
- `routeConfig` - Deprecated, use `request.routeOptions.config` instead. The
|
|
49
|
-
route [`config`](./Routes.md#routes-config)
|
|
50
|
-
object.
|
|
51
40
|
- `routeOptions` - The route [`option`](./Routes.md#routes-options) object
|
|
52
41
|
- `bodyLimit` - either server limit or route limit
|
|
53
42
|
- `config` - the [`config`](./Routes.md#routes-config) object for this route
|
package/docs/Reference/Routes.md
CHANGED
|
@@ -32,10 +32,9 @@ fastify.route(options)
|
|
|
32
32
|
### Routes options
|
|
33
33
|
<a id="options"></a>
|
|
34
34
|
|
|
35
|
-
* `method`: currently it supports `
|
|
36
|
-
`
|
|
37
|
-
|
|
38
|
-
`'REPORT'` and `'MKCALENDAR'`.
|
|
35
|
+
* `method`: currently it supports `GET`, `HEAD`, `TRACE`, `DELETE`,
|
|
36
|
+
`OPTIONS`, `PATCH`, `PUT` and `POST`. To accept more methods,
|
|
37
|
+
the [`addHttpMethod`](./Server.md#addHttpMethod) must be used.
|
|
39
38
|
It could also be an array of methods.
|
|
40
39
|
* `url`: the path of the URL to match this route (alias: `path`).
|
|
41
40
|
* `schema`: an object containing the schemas for the request and response. They
|
|
@@ -190,24 +189,6 @@ The above route declaration is more *Hapi*-like, but if you prefer an
|
|
|
190
189
|
|
|
191
190
|
`fastify.patch(path, [options], handler)`
|
|
192
191
|
|
|
193
|
-
`fastify.propfind(path, [options], handler)`
|
|
194
|
-
|
|
195
|
-
`fastify.proppatch(path, [options], handler)`
|
|
196
|
-
|
|
197
|
-
`fastify.mkcol(path, [options], handler)`
|
|
198
|
-
|
|
199
|
-
`fastify.copy(path, [options], handler)`
|
|
200
|
-
|
|
201
|
-
`fastify.move(path, [options], handler)`
|
|
202
|
-
|
|
203
|
-
`fastify.lock(path, [options], handler)`
|
|
204
|
-
|
|
205
|
-
`fastify.unlock(path, [options], handler)`
|
|
206
|
-
|
|
207
|
-
`fastify.trace(path, [options], handler)`
|
|
208
|
-
|
|
209
|
-
`fastify.search(path, [options], handler)`
|
|
210
|
-
|
|
211
192
|
Example:
|
|
212
193
|
```js
|
|
213
194
|
const opts = {
|
|
@@ -633,7 +614,7 @@ retrieve it in the handler.
|
|
|
633
614
|
const fastify = require('fastify')()
|
|
634
615
|
|
|
635
616
|
function handler (req, reply) {
|
|
636
|
-
reply.send(reply.
|
|
617
|
+
reply.send(reply.routeOptions.config.output)
|
|
637
618
|
}
|
|
638
619
|
|
|
639
620
|
fastify.get('/en', { config: { output: 'hello world!' } }, handler)
|
package/docs/Reference/Server.md
CHANGED
|
@@ -26,7 +26,6 @@ describes the properties available in that options object.
|
|
|
26
26
|
- [`logger`](#logger)
|
|
27
27
|
- [`disableRequestLogging`](#disablerequestlogging)
|
|
28
28
|
- [`serverFactory`](#serverfactory)
|
|
29
|
-
- [`jsonShorthand`](#jsonshorthand)
|
|
30
29
|
- [`caseSensitive`](#casesensitive)
|
|
31
30
|
- [`allowUnsafeRegex`](#allowunsaferegex)
|
|
32
31
|
- [`requestIdHeader`](#requestidheader)
|
|
@@ -68,6 +67,7 @@ describes the properties available in that options object.
|
|
|
68
67
|
- [log](#log)
|
|
69
68
|
- [version](#version)
|
|
70
69
|
- [inject](#inject)
|
|
70
|
+
- [addHttpMethod](#addHttpMethod)
|
|
71
71
|
- [addSchema](#addschema)
|
|
72
72
|
- [getSchemas](#getschemas)
|
|
73
73
|
- [getSchema](#getschema)
|
|
@@ -270,6 +270,8 @@ fastify.get('///foo//bar//', function (req, reply) {
|
|
|
270
270
|
### `maxParamLength`
|
|
271
271
|
<a id="factory-max-param-length"></a>
|
|
272
272
|
|
|
273
|
+
+ Default: `100`
|
|
274
|
+
|
|
273
275
|
You can set a custom length for parameters in parametric (standard, regex, and
|
|
274
276
|
multi) routes by using `maxParamLength` option; the default value is 100
|
|
275
277
|
characters. If the maximum length limit is reached, the not found route will
|
|
@@ -440,45 +442,6 @@ custom server you must be sure to have the same API exposed. If not, you can
|
|
|
440
442
|
enhance the server instance inside the `serverFactory` function before the
|
|
441
443
|
`return` statement.
|
|
442
444
|
|
|
443
|
-
|
|
444
|
-
### `jsonShorthand`
|
|
445
|
-
<a id="schema-json-shorthand"></a>
|
|
446
|
-
|
|
447
|
-
+ Default: `true`
|
|
448
|
-
|
|
449
|
-
By default, Fastify will automatically infer the root properties
|
|
450
|
-
of JSON Schemas if it does not find valid root properties according to the JSON
|
|
451
|
-
Schema spec. If you wish to implement your own schema validation compiler, to
|
|
452
|
-
parse schemas as JTD instead of JSON Schema for example, then you can explicitly
|
|
453
|
-
set this option to `false` to make sure the schemas you receive are unmodified
|
|
454
|
-
and are not being treated internally as JSON Schema.
|
|
455
|
-
|
|
456
|
-
Fastify does not throw on invalid schemas so if this option is set to `false`
|
|
457
|
-
in an existing project, check that none of your existing schemas become
|
|
458
|
-
invalid as a result, as they will be treated as catch-alls.
|
|
459
|
-
|
|
460
|
-
```js
|
|
461
|
-
const AjvJTD = require('ajv/dist/jtd'/* only valid for AJV v7+ */)
|
|
462
|
-
const ajv = new AjvJTD({
|
|
463
|
-
// This would let you throw at start for invalid JTD schema objects
|
|
464
|
-
allErrors: process.env.NODE_ENV === 'development'
|
|
465
|
-
})
|
|
466
|
-
const fastify = Fastify({ jsonShorthand: false })
|
|
467
|
-
fastify.setValidatorCompiler(({ schema }) => {
|
|
468
|
-
return ajv.compile(schema)
|
|
469
|
-
})
|
|
470
|
-
fastify.post('/', {
|
|
471
|
-
schema: {
|
|
472
|
-
body: {
|
|
473
|
-
properties: {
|
|
474
|
-
foo: { type: 'uint8' }
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
},
|
|
478
|
-
handler (req, reply) { reply.send({ ok: 1 }) }
|
|
479
|
-
})
|
|
480
|
-
```
|
|
481
|
-
|
|
482
445
|
### `caseSensitive`
|
|
483
446
|
<a id="factory-case-sensitive"></a>
|
|
484
447
|
|
|
@@ -1305,6 +1268,33 @@ used by plugins.
|
|
|
1305
1268
|
Fake HTTP injection (for testing purposes)
|
|
1306
1269
|
[here](../Guides/Testing.md#benefits-of-using-fastifyinject).
|
|
1307
1270
|
|
|
1271
|
+
#### addHttpMethod
|
|
1272
|
+
<a id="addHttpMethod"></a>
|
|
1273
|
+
|
|
1274
|
+
Fastify supports the `GET`, `HEAD`, `TRACE`, `DELETE`, `OPTIONS`,
|
|
1275
|
+
`PATCH`, `PUT` and `POST` HTTP methods by default.
|
|
1276
|
+
The `addHttpMethod` method allows to add any non standard HTTP
|
|
1277
|
+
methods to the server that are [supported by Node.js](https://nodejs.org/api/http.html#httpmethods).
|
|
1278
|
+
|
|
1279
|
+
```js
|
|
1280
|
+
// Add a new HTTP method called 'MKCOL' that supports a request body
|
|
1281
|
+
fastify.addHttpMethod('MKCOL', { hasBody: true, })
|
|
1282
|
+
|
|
1283
|
+
// Add a new HTTP method called 'COPY' that does not support a request body
|
|
1284
|
+
fastify.addHttpMethod('COPY')
|
|
1285
|
+
```
|
|
1286
|
+
|
|
1287
|
+
After calling `addHttpMethod`, it is possible to use the route shorthand
|
|
1288
|
+
methods to define routes for the new HTTP method:
|
|
1289
|
+
|
|
1290
|
+
```js
|
|
1291
|
+
fastify.addHttpMethod('MKCOL', { hasBody: true })
|
|
1292
|
+
fastify.mkcol('/', (req, reply) => {
|
|
1293
|
+
// Handle the 'MKCOL' request
|
|
1294
|
+
})
|
|
1295
|
+
```
|
|
1296
|
+
|
|
1297
|
+
|
|
1308
1298
|
#### addSchema
|
|
1309
1299
|
<a id="add-schema"></a>
|
|
1310
1300
|
|
|
@@ -154,8 +154,8 @@ fastify.register(pluginWithJsonSchema)
|
|
|
154
154
|
fastify.register(pluginWithTypebox)
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
It's also important to mention that
|
|
158
|
-
_currently_ is not possible to avoid multiple registrations on routes when
|
|
157
|
+
It's also important to mention that since the types don't propagate globally,
|
|
158
|
+
_currently_ it is not possible to avoid multiple registrations on routes when
|
|
159
159
|
dealing with several scopes, see below:
|
|
160
160
|
|
|
161
161
|
```ts
|
|
@@ -210,24 +210,23 @@ And a `zod` wrapper by a third party called [`fastify-type-provider-zod`](https:
|
|
|
210
210
|
They simplify schema validation setup and you can read more about them in [Type
|
|
211
211
|
Providers](./Type-Providers.md) page.
|
|
212
212
|
|
|
213
|
-
Below is how to setup schema validation using
|
|
214
|
-
`json-schema-to-ts` packages
|
|
213
|
+
Below is how to setup schema validation using the `typebox`,
|
|
214
|
+
`json-schema-to-typescript`, and `json-schema-to-ts` packages without type
|
|
215
|
+
providers.
|
|
215
216
|
|
|
216
217
|
#### TypeBox
|
|
217
218
|
|
|
218
|
-
A useful library for building types and a schema at once is
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
With TypeBox you define your schema within your code and use them
|
|
222
|
-
directly as types or schemas as you need them.
|
|
219
|
+
A useful library for building types and a schema at once is [TypeBox](https://www.npmjs.com/package/@sinclair/typebox).
|
|
220
|
+
With TypeBox you define your schema within your code and use them directly as
|
|
221
|
+
types or schemas as you need them.
|
|
223
222
|
|
|
224
223
|
When you want to use it for validation of some payload in a fastify route you
|
|
225
224
|
can do it as follows:
|
|
226
225
|
|
|
227
|
-
1. Install `typebox`
|
|
226
|
+
1. Install `typebox` in your project.
|
|
228
227
|
|
|
229
228
|
```bash
|
|
230
|
-
npm i @sinclair/typebox
|
|
229
|
+
npm i @sinclair/typebox
|
|
231
230
|
```
|
|
232
231
|
|
|
233
232
|
2. Define the schema you need with `Type` and create the respective type with
|
|
@@ -248,10 +247,9 @@ can do it as follows:
|
|
|
248
247
|
|
|
249
248
|
```typescript
|
|
250
249
|
import Fastify from 'fastify'
|
|
251
|
-
import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'
|
|
252
250
|
// ...
|
|
253
251
|
|
|
254
|
-
const fastify = Fastify()
|
|
252
|
+
const fastify = Fastify()
|
|
255
253
|
|
|
256
254
|
fastify.post<{ Body: UserType, Reply: UserType }>(
|
|
257
255
|
'/',
|
|
@@ -271,12 +269,12 @@ can do it as follows:
|
|
|
271
269
|
)
|
|
272
270
|
```
|
|
273
271
|
|
|
274
|
-
####
|
|
272
|
+
#### json-schema-to-typescript
|
|
275
273
|
|
|
276
|
-
In the last example we used
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
274
|
+
In the last example we used Typebox to define the types and schemas for our
|
|
275
|
+
route. Many users will already be using JSON Schemas to define these properties,
|
|
276
|
+
and luckily there is a way to transform existing JSON Schemas into TypeScript
|
|
277
|
+
interfaces!
|
|
280
278
|
|
|
281
279
|
1. If you did not complete the 'Getting Started' example, go back and follow
|
|
282
280
|
steps 1-4 first.
|
|
@@ -596,7 +594,7 @@ your plugin.
|
|
|
596
594
|
}
|
|
597
595
|
|
|
598
596
|
module.exports = fp(myPlugin, {
|
|
599
|
-
fastify: '
|
|
597
|
+
fastify: '5.x',
|
|
600
598
|
name: 'my-plugin' // this is used by fastify-plugin to derive the property name
|
|
601
599
|
})
|
|
602
600
|
```
|
|
@@ -1137,7 +1135,7 @@ RawRequestDefaultExpression<http2.Http2Server> // -> http2.Http2ServerRequest
|
|
|
1137
1135
|
|
|
1138
1136
|
#### Reply
|
|
1139
1137
|
|
|
1140
|
-
##### fastify.FastifyReply< [RawServer][RawServerGeneric], [RawRequest][RawRequestGeneric], [RawReply][RawReplyGeneric], [
|
|
1138
|
+
##### fastify.FastifyReply<[RequestGeneric][FastifyRequestGenericInterface], [RawServer][RawServerGeneric], [RawRequest][RawRequestGeneric], [RawReply][RawReplyGeneric], [ContextConfig][ContextConfigGeneric]>
|
|
1141
1139
|
[src](https://github.com/fastify/fastify/blob/main/types/reply.d.ts#L32)
|
|
1142
1140
|
|
|
1143
1141
|
This interface contains the custom properties that Fastify adds to the standard
|