fastify 4.0.0-rc.3 → 4.0.0-rc.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 +1 -0
- package/build/build-validation.js +2 -0
- package/docs/Guides/Ecosystem.md +21 -9
- package/docs/Guides/Testing.md +3 -1
- package/docs/Reference/Logging.md +10 -5
- package/docs/Reference/Routes.md +1 -1
- package/docs/Reference/Server.md +27 -2
- package/docs/Reference/TypeScript.md +1 -1
- package/fastify.d.ts +1 -0
- package/fastify.js +3 -2
- package/lib/configValidator.js +123 -94
- package/lib/request.js +2 -2
- package/lib/route.js +3 -1
- package/lib/validation.js +5 -1
- package/package.json +7 -7
- package/test/decorator.test.js +146 -0
- package/test/internals/initialConfig.test.js +5 -1
- package/test/plugin.test.js +18 -14
- package/test/route-prefix.test.js +250 -0
- package/test/router-options.test.js +61 -0
- package/test/schema-feature.test.js +24 -0
- package/test/types/fastify.test-d.ts +1 -0
- package/test/types/instance.test-d.ts +1 -0
- package/test/types/route.test-d.ts +14 -0
- package/types/instance.d.ts +1 -0
- package/types/route.d.ts +1 -1
- package/types/type-provider.d.ts +1 -1
package/README.md
CHANGED
|
@@ -265,6 +265,7 @@ Team members are listed in alphabetical order.
|
|
|
265
265
|
* [__Maksim Sinik__](https://github.com/fox1t), <https://twitter.com/maksimsinik>, <https://www.npmjs.com/~fox1t>
|
|
266
266
|
* [__Frazer Smith__](https://github.com/Fdawgs), <https://www.npmjs.com/~fdawgs>
|
|
267
267
|
* [__Manuel Spigolon__](https://github.com/eomm), <https://twitter.com/manueomm>, <https://www.npmjs.com/~eomm>
|
|
268
|
+
* [__Rafael Gonzaga__](https://github.com/rafaelgss), <https://twitter.com/_rafaelgss>, <https://www.npmjs.com/~rafaelgss>
|
|
268
269
|
|
|
269
270
|
### Great Contributors
|
|
270
271
|
Great contributors on a specific area in the Fastify ecosystem will be invited to join this group by Lead Maintainers.
|
|
@@ -33,6 +33,7 @@ const defaultInitOptions = {
|
|
|
33
33
|
disableRequestLogging: false,
|
|
34
34
|
jsonShorthand: true,
|
|
35
35
|
ignoreTrailingSlash: false,
|
|
36
|
+
ignoreDuplicateSlashes: false,
|
|
36
37
|
maxParamLength: 100,
|
|
37
38
|
onProtoPoisoning: 'error',
|
|
38
39
|
onConstructorPoisoning: 'error',
|
|
@@ -76,6 +77,7 @@ const schema = {
|
|
|
76
77
|
then: { setDefaultValue: true }
|
|
77
78
|
},
|
|
78
79
|
ignoreTrailingSlash: { type: 'boolean', default: defaultInitOptions.ignoreTrailingSlash },
|
|
80
|
+
ignoreDuplicateSlashes: { type: 'boolean', default: defaultInitOptions.ignoreDuplicateSlashes },
|
|
79
81
|
disableRequestLogging: {
|
|
80
82
|
type: 'boolean',
|
|
81
83
|
default: false
|
package/docs/Guides/Ecosystem.md
CHANGED
|
@@ -8,9 +8,6 @@ section.
|
|
|
8
8
|
|
|
9
9
|
#### [Core](#core)
|
|
10
10
|
|
|
11
|
-
- [`aws-lambda-fastify`](https://github.com/fastify/aws-lambda-fastify) allows you to
|
|
12
|
-
easily build serverless web applications/services and RESTful APIs using Fastify
|
|
13
|
-
on top of AWS Lambda and Amazon API Gateway.
|
|
14
11
|
- [`@fastify/accepts`](https://github.com/fastify/fastify-accepts) to have
|
|
15
12
|
[accepts](https://www.npmjs.com/package/accepts) in your request object.
|
|
16
13
|
- [`@fastify/accepts-serializer`](https://github.com/fastify/fastify-accepts-serializer)
|
|
@@ -19,9 +16,6 @@ section.
|
|
|
19
16
|
functions in Fastify.
|
|
20
17
|
- [`@fastify/autoload`](https://github.com/fastify/fastify-autoload) Require all
|
|
21
18
|
plugins in a directory.
|
|
22
|
-
- [`fastify-awilix`](https://github.com/fastify/fastify-awilix) Dependency
|
|
23
|
-
injection support for Fastify, based on
|
|
24
|
-
[awilix](https://github.com/jeffijoe/awilix).
|
|
25
19
|
- [`@fastify/basic-auth`](https://github.com/fastify/fastify-basic-auth) Basic
|
|
26
20
|
auth plugin for Fastify.
|
|
27
21
|
- [`@fastify/bearer-auth`](https://github.com/fastify/fastify-bearer-auth) Bearer
|
|
@@ -93,9 +87,6 @@ section.
|
|
|
93
87
|
to forward the current HTTP request to another server.
|
|
94
88
|
- [`@fastify/routes`](https://github.com/fastify/fastify-routes) Plugin that
|
|
95
89
|
provides a `Map` of routes.
|
|
96
|
-
- [`fastify-schedule`](https://github.com/fastify/fastify-schedule) Plugin for
|
|
97
|
-
scheduling periodic jobs, based on
|
|
98
|
-
[toad-scheduler](https://github.com/kibertoad/toad-scheduler).
|
|
99
90
|
- [`@fastify/sensible`](https://github.com/fastify/fastify-sensible) Defaults for
|
|
100
91
|
Fastify that everyone can agree on. It adds some useful decorators such as
|
|
101
92
|
HTTP errors and assertions, but also more request and reply methods.
|
|
@@ -110,6 +101,17 @@ section.
|
|
|
110
101
|
support for Fastify. Built upon [ws](https://github.com/websockets/ws).
|
|
111
102
|
- [`@fastify/url-data`](https://github.com/fastify/fastify-url-data) Decorate the
|
|
112
103
|
`Request` object with a method to access raw URL components.
|
|
104
|
+
- [`any-schema-you-like`](https://github.com/fastify/any-schema-you-like) Save multiple
|
|
105
|
+
schemas and decide which one to use to serialize the payload
|
|
106
|
+
- [`aws-lambda-fastify`](https://github.com/fastify/aws-lambda-fastify) allows you to
|
|
107
|
+
easily build serverless web applications/services and RESTful APIs using Fastify
|
|
108
|
+
on top of AWS Lambda and Amazon API Gateway.
|
|
109
|
+
- [`fastify-awilix`](https://github.com/fastify/fastify-awilix) Dependency
|
|
110
|
+
injection support for Fastify, based on
|
|
111
|
+
[awilix](https://github.com/jeffijoe/awilix).
|
|
112
|
+
- [`fastify-schedule`](https://github.com/fastify/fastify-schedule) Plugin for
|
|
113
|
+
scheduling periodic jobs, based on
|
|
114
|
+
[toad-scheduler](https://github.com/kibertoad/toad-scheduler).
|
|
113
115
|
- [`middie`](https://github.com/fastify/middie) Middleware engine for Fastify.
|
|
114
116
|
- [`point-of-view`](https://github.com/fastify/point-of-view) Templates
|
|
115
117
|
rendering (_ejs, pug, handlebars, marko_) plugin support for Fastify.
|
|
@@ -163,6 +165,9 @@ section.
|
|
|
163
165
|
- [`fastify-amqp`](https://github.com/RafaelGSS/fastify-amqp) Fastify AMQP
|
|
164
166
|
connection plugin, to use with RabbitMQ or another connector. Just a wrapper
|
|
165
167
|
to [`amqplib`](https://github.com/squaremo/amqp.node).
|
|
168
|
+
- [`fastify-amqp-async`](https://github.com/kffl/fastify-amqp-async) Fastify
|
|
169
|
+
AMQP plugin with a Promise-based API provided by
|
|
170
|
+
[`amqplib-as-promised`](https://github.com/twawszczak/amqplib-as-promised).
|
|
166
171
|
- [`fastify-angular-universal`](https://github.com/exequiel09/fastify-angular-universal)
|
|
167
172
|
Angular server-side rendering support using
|
|
168
173
|
[`@angular/platform-server`](https://github.com/angular/angular/tree/master/packages/platform-server)
|
|
@@ -306,6 +311,8 @@ section.
|
|
|
306
311
|
user scope verifier.
|
|
307
312
|
- [`fastify-jwt-webapp`](https://github.com/charlesread/fastify-jwt-webapp) JWT
|
|
308
313
|
authentication for Fastify-based web apps.
|
|
314
|
+
- [`fastify-kafkajs`](https://github.com/kffl/fastify-kafkajs) Fastify plugin
|
|
315
|
+
that adds support for KafkaJS - a modern Apache Kafka client library.
|
|
309
316
|
- [`fastify-knexjs`](https://github.com/chapuletta/fastify-knexjs) Fastify
|
|
310
317
|
plugin for support KnexJS Query Builder.
|
|
311
318
|
- [`fastify-knexjs-mock`](https://github.com/chapuletta/fastify-knexjs-mock)
|
|
@@ -346,6 +353,7 @@ section.
|
|
|
346
353
|
for handling multipart/form-data, which is primarily used for uploading files.
|
|
347
354
|
- [`fastify-nats`](https://github.com/mahmed8003/fastify-nats) Plugin to share
|
|
348
355
|
[NATS](https://nats.io) client across Fastify.
|
|
356
|
+
- [`fastify-next-auth`](https://github.com/wobsoriano/fastify-next-auth) NextAuth.js plugin for Fastify.
|
|
349
357
|
- [`fastify-no-additional-properties`](https://github.com/greguz/fastify-no-additional-properties)
|
|
350
358
|
Add `additionalProperties: false` by default to your JSON Schemas.
|
|
351
359
|
- [`fastify-no-icon`](https://github.com/jsumners/fastify-no-icon) Plugin to
|
|
@@ -521,3 +529,7 @@ section.
|
|
|
521
529
|
Fastify.
|
|
522
530
|
- [`sequelize-fastify`](https://github.com/hsynlms/sequelize-fastify) A simple
|
|
523
531
|
and lightweight Sequelize plugin for Fastify.
|
|
532
|
+
|
|
533
|
+
#### [Community Tools](#community-tools)
|
|
534
|
+
- [`fast-maker`](https://github.com/imjuni/fast-maker) route configuration generator by
|
|
535
|
+
directory structure.
|
package/docs/Guides/Testing.md
CHANGED
|
@@ -26,13 +26,16 @@ and production environment requires bit more configuration:
|
|
|
26
26
|
```js
|
|
27
27
|
const fastify = require('fastify')({
|
|
28
28
|
logger: {
|
|
29
|
-
|
|
29
|
+
transport:
|
|
30
30
|
environment === 'development'
|
|
31
31
|
? {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
target: 'pino-pretty',
|
|
33
|
+
options: {
|
|
34
|
+
translateTime: 'HH:MM:ss Z',
|
|
35
|
+
ignore: 'pid,hostname'
|
|
36
|
+
}
|
|
34
37
|
}
|
|
35
|
-
:
|
|
38
|
+
: undefined
|
|
36
39
|
}
|
|
37
40
|
})
|
|
38
41
|
```
|
|
@@ -119,7 +122,9 @@ below (even if it is *not recommended*):
|
|
|
119
122
|
```js
|
|
120
123
|
const fastify = require('fastify')({
|
|
121
124
|
logger: {
|
|
122
|
-
|
|
125
|
+
transport: {
|
|
126
|
+
target: 'pino-pretty'
|
|
127
|
+
},
|
|
123
128
|
serializers: {
|
|
124
129
|
res (reply) {
|
|
125
130
|
// The default
|
package/docs/Reference/Routes.md
CHANGED
|
@@ -114,7 +114,7 @@ fastify.route(options)
|
|
|
114
114
|
* `slash`: Will register only `/prefix/`.
|
|
115
115
|
* `no-slash`: Will register only `/prefix`.
|
|
116
116
|
|
|
117
|
-
Note: this option does not override `
|
|
117
|
+
Note: this option does not override `ignoreTrailingSlash` in [Server](./Server.md) configuration.
|
|
118
118
|
|
|
119
119
|
* `request` is defined in [Request](./Request.md).
|
|
120
120
|
|
package/docs/Reference/Server.md
CHANGED
|
@@ -17,6 +17,7 @@ describes the properties available in that options object.
|
|
|
17
17
|
- [`maxRequestsPerSocket`](#maxrequestspersocket)
|
|
18
18
|
- [`requestTimeout`](#requesttimeout)
|
|
19
19
|
- [`ignoreTrailingSlash`](#ignoretrailingslash)
|
|
20
|
+
- [`ignoreDuplicateSlashes`](#ignoreduplicateslashes)
|
|
20
21
|
- [`maxParamLength`](#maxparamlength)
|
|
21
22
|
- [`bodyLimit`](#bodylimit)
|
|
22
23
|
- [`onProtoPoisoning`](#onprotopoisoning)
|
|
@@ -203,6 +204,29 @@ fastify.get('/bar', function (req, reply) {
|
|
|
203
204
|
})
|
|
204
205
|
```
|
|
205
206
|
|
|
207
|
+
### `ignoreDuplicateSlashes`
|
|
208
|
+
<a id="factory-ignore-duplicate-slashes"></a>
|
|
209
|
+
|
|
210
|
+
Fastify uses [find-my-way](https://github.com/delvedor/find-my-way) to handle
|
|
211
|
+
routing. You can use `ignoreDuplicateSlashes` option to remove duplicate slashes
|
|
212
|
+
from the path. It removes duplicate slashes in the route path and in the request
|
|
213
|
+
URL. This option applies to *all* route registrations for the resulting server instance.
|
|
214
|
+
|
|
215
|
+
Note that when `ignoreTrailingSlash` and `ignoreDuplicateSlashes` are both set to true, Fastify will remove duplicate slashes, and then trailing slashes, meaning //a//b//c// will be converted to /a/b/c.
|
|
216
|
+
|
|
217
|
+
+ Default: `false`
|
|
218
|
+
|
|
219
|
+
```js
|
|
220
|
+
const fastify = require('fastify')({
|
|
221
|
+
ignoreDuplicateSlashes: true
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
// registers "/foo/bar/"
|
|
225
|
+
fastify.get('///foo//bar//', function (req, reply) {
|
|
226
|
+
reply.send('foo')
|
|
227
|
+
})
|
|
228
|
+
```
|
|
229
|
+
|
|
206
230
|
### `maxParamLength`
|
|
207
231
|
<a id="factory-max-param-length"></a>
|
|
208
232
|
|
|
@@ -1061,7 +1085,8 @@ fastify.register(function (instance, opts, done) {
|
|
|
1061
1085
|
#### pluginName
|
|
1062
1086
|
<a id="pluginName"></a>
|
|
1063
1087
|
|
|
1064
|
-
Name of the current plugin.
|
|
1088
|
+
Name of the current plugin. The root plugin is called `'fastify'`.
|
|
1089
|
+
There are three ways to define a name (in order).
|
|
1065
1090
|
|
|
1066
1091
|
1. If you use [fastify-plugin](https://github.com/fastify/fastify-plugin) the
|
|
1067
1092
|
metadata `name` is used.
|
|
@@ -1078,7 +1103,7 @@ Important: If you have to deal with nested plugins, the name differs with the
|
|
|
1078
1103
|
usage of the [fastify-plugin](https://github.com/fastify/fastify-plugin) because
|
|
1079
1104
|
no new scope is created and therefore we have no place to attach contextual
|
|
1080
1105
|
data. In that case, the plugin name will represent the boot order of all
|
|
1081
|
-
involved plugins in the format of `plugin-A -> plugin-B`.
|
|
1106
|
+
involved plugins in the format of `fastify -> plugin-A -> plugin-B`.
|
|
1082
1107
|
|
|
1083
1108
|
#### log
|
|
1084
1109
|
<a id="log"></a>
|
|
@@ -1284,7 +1284,7 @@ handlers respectfully.
|
|
|
1284
1284
|
|
|
1285
1285
|
[src](https://github.com/fastify/fastify/blob/main/types/route.d.ts#L78)
|
|
1286
1286
|
|
|
1287
|
-
An interface
|
|
1287
|
+
An interface that extends RouteShorthandOptions and adds the following three
|
|
1288
1288
|
required properties:
|
|
1289
1289
|
1. `method` which corresponds to a singular [HTTPMethod][HTTPMethods] or a list
|
|
1290
1290
|
of [HTTPMethods][HTTPMethods]
|
package/fastify.d.ts
CHANGED
|
@@ -106,6 +106,7 @@ export type FastifyServerOptions<
|
|
|
106
106
|
Logger extends FastifyBaseLogger = FastifyLoggerInstance
|
|
107
107
|
> = {
|
|
108
108
|
ignoreTrailingSlash?: boolean,
|
|
109
|
+
ignoreDuplicateSlashes?: boolean,
|
|
109
110
|
connectionTimeout?: number,
|
|
110
111
|
keepAliveTimeout?: number,
|
|
111
112
|
maxRequestsPerSocket?: number,
|
package/fastify.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const VERSION = '4.0.0-rc.
|
|
3
|
+
const VERSION = '4.0.0-rc.4'
|
|
4
4
|
|
|
5
5
|
const Avvio = require('avvio')
|
|
6
6
|
const http = require('http')
|
|
@@ -166,6 +166,7 @@ function fastify (options) {
|
|
|
166
166
|
onBadUrl,
|
|
167
167
|
constraints,
|
|
168
168
|
ignoreTrailingSlash: options.ignoreTrailingSlash || defaultInitOptions.ignoreTrailingSlash,
|
|
169
|
+
ignoreDuplicateSlashes: options.ignoreDuplicateSlashes || defaultInitOptions.ignoreDuplicateSlashes,
|
|
169
170
|
maxParamLength: options.maxParamLength || defaultInitOptions.maxParamLength,
|
|
170
171
|
caseSensitive: options.caseSensitive,
|
|
171
172
|
allowUnsafeRegex: options.allowUnsafeRegex || defaultInitOptions.allowUnsafeRegex,
|
|
@@ -218,7 +219,7 @@ function fastify (options) {
|
|
|
218
219
|
[kRequest]: Request.buildRequest(Request, options.trustProxy),
|
|
219
220
|
[kFourOhFour]: fourOhFour,
|
|
220
221
|
[pluginUtils.registeredPlugins]: [],
|
|
221
|
-
[kPluginNameChain]: [],
|
|
222
|
+
[kPluginNameChain]: ['fastify'],
|
|
222
223
|
[kAvvioBoot]: null,
|
|
223
224
|
// routing method
|
|
224
225
|
routing: httpHandler,
|