fastify 2.7.1 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -4
- package/build/build-validation.js +8 -0
- package/docs/Benchmarking.md +2 -2
- package/docs/ContentTypeParser.md +12 -10
- package/docs/Decorators.md +14 -14
- package/docs/Ecosystem.md +7 -1
- package/docs/Errors.md +13 -8
- package/docs/Fluent-Schema.md +9 -12
- package/docs/Getting-Started.md +29 -25
- package/docs/HTTP2.md +1 -1
- package/docs/Hooks.md +201 -186
- package/docs/LTS.md +6 -7
- package/docs/Logging.md +10 -10
- package/docs/Middleware.md +59 -0
- package/docs/Plugins-Guide.md +52 -52
- package/docs/Plugins.md +3 -0
- package/docs/Reply.md +47 -3
- package/docs/Routes.md +120 -8
- package/docs/Server.md +69 -3
- package/docs/Serverless.md +76 -4
- package/docs/TypeScript.md +33 -10
- package/docs/Validation-and-Serialization.md +137 -1
- package/examples/typescript-server.ts +1 -1
- package/fastify.d.ts +52 -13
- package/fastify.js +68 -7
- package/lib/configValidator.js +99 -52
- package/lib/contentTypeParser.js +4 -4
- package/lib/context.js +2 -1
- package/lib/errors.js +21 -18
- package/lib/fourOhFour.js +10 -10
- package/lib/handleRequest.js +1 -2
- package/lib/logger.js +2 -2
- package/lib/pluginUtils.js +32 -0
- package/lib/reply.js +41 -6
- package/lib/route.js +37 -9
- package/lib/schemas.js +23 -12
- package/lib/symbols.js +4 -1
- package/lib/validation.js +15 -9
- package/lib/wrapThenable.js +1 -1
- package/package.json +34 -26
- package/test/404s.test.js +41 -1
- package/test/async-await.js +66 -0
- package/test/custom-parser.test.js +1 -1
- package/test/custom-querystring-parser.test.js +1 -1
- package/test/decorator.test.js +48 -0
- package/test/emit-warning.test.js +3 -3
- package/test/fastify-instance.test.js +29 -0
- package/test/helper.js +7 -7
- package/test/hooks-async.js +4 -3
- package/test/hooks.test.js +27 -8
- package/test/input-validation.test.js +126 -0
- package/test/internals/errors.test.js +9 -1
- package/test/internals/initialConfig.test.js +4 -2
- package/test/internals/plugin.test.js +4 -4
- package/test/internals/reply.test.js +78 -6
- package/test/internals/schemas.test.js +30 -0
- package/test/internals/validation.test.js +18 -0
- package/test/listen.test.js +1 -1
- package/test/logger.test.js +314 -1
- package/test/plugin.test.js +171 -0
- package/test/promises.test.js +55 -0
- package/test/proto-poisoning.test.js +76 -0
- package/test/route-hooks.test.js +109 -91
- package/test/route-prefix.test.js +1 -1
- package/test/schemas.test.js +450 -0
- package/test/shared-schemas.test.js +2 -2
- package/test/stream.test.js +10 -6
- package/test/throw.test.js +48 -2
- package/test/types/index.ts +86 -1
- package/test/validation-error-handling.test.js +3 -3
- package/test/versioned-routes.test.js +1 -1
- package/docs/Middlewares.md +0 -59
package/README.md
CHANGED
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
<div align="center">
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+
[](https://dev.azure.com/fastify/fastify/_build/latest?definitionId=1)
|
|
11
|
+
[](https://snyk.io/test/github/fastify/fastify)
|
|
9
12
|
[](https://coveralls.io/github/fastify/fastify?branch=master)
|
|
10
13
|
[](http://standardjs.com/)
|
|
11
14
|
|
|
@@ -145,10 +148,11 @@ matters to you.
|
|
|
145
148
|
* <a href="https://github.com/fastify/fastify/blob/master/docs/Server.md"><code><b>Server</b></code></a>
|
|
146
149
|
* <a href="https://github.com/fastify/fastify/blob/master/docs/Routes.md"><code><b>Routes</b></code></a>
|
|
147
150
|
* <a href="https://github.com/fastify/fastify/blob/master/docs/Logging.md"><code><b>Logging</b></code></a>
|
|
148
|
-
* <a href="https://github.com/fastify/fastify/blob/master/docs/
|
|
151
|
+
* <a href="https://github.com/fastify/fastify/blob/master/docs/Middleware.md"><code><b>Middleware</b></code></a>
|
|
149
152
|
* <a href="https://github.com/fastify/fastify/blob/master/docs/Hooks.md"><code><b>Hooks</b></code></a>
|
|
150
153
|
* <a href="https://github.com/fastify/fastify/blob/master/docs/Decorators.md"><code><b>Decorators</b></code></a>
|
|
151
154
|
* <a href="https://github.com/fastify/fastify/blob/master/docs/Validation-and-Serialization.md"><code><b>Validation and Serialization</b></code></a>
|
|
155
|
+
* <a href="https://github.com/fastify/fastify/blob/master/docs/Fluent-Schema.md"><code><b>Fluent Schema</b></code></a>
|
|
152
156
|
* <a href="https://github.com/fastify/fastify/blob/master/docs/Lifecycle.md"><code><b>Lifecycle</b></code></a>
|
|
153
157
|
* <a href="https://github.com/fastify/fastify/blob/master/docs/Reply.md"><code><b>Reply</b></code></a>
|
|
154
158
|
* <a href="https://github.com/fastify/fastify/blob/master/docs/Request.md"><code><b>Request</b></code></a>
|
|
@@ -190,11 +194,11 @@ Team members are listed in alphabetical order.
|
|
|
190
194
|
* [__Matteo Collina__](https://github.com/mcollina), <https://twitter.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
|
|
191
195
|
* [__Tomas Della Vedova__](https://github.com/delvedor), <https://twitter.com/delvedor>, <https://www.npmjs.com/~delvedor>
|
|
192
196
|
* [__Dustin Deus__](https://github.com/StarpTech), <https://twitter.com/dustindeus>, <https://www.npmjs.com/~starptech>
|
|
197
|
+
* [__Denis Fäcke__](https://github.com/SerayaEryn), <https://twitter.com/serayaeryn>, <https://www.npmjs.com/~serayaeryn>
|
|
193
198
|
* [__Luciano Mammino__](https://github.com/lmammino), <https://twitter.com/loige>, <https://www.npmjs.com/~lmammino>
|
|
194
199
|
* [__Cemre Mengu__](https://github.com/cemremengu), <https://twitter.com/cemremengu>, <https://www.npmjs.com/~cemremengu>
|
|
195
200
|
* [__Manuel Spigolon__](https://github.com/eomm), <https://twitter.com/manueomm>, <https://www.npmjs.com/~eomm>
|
|
196
201
|
* [__James Sumners__](https://github.com/jsumners), <https://twitter.com/jsumners79>, <https://www.npmjs.com/~jsumners>
|
|
197
|
-
* [__Nathan Woltman__](https://github.com/nwoltman), <https://twitter.com/NathanWoltman>, <https://www.npmjs.com/~nwoltman>
|
|
198
202
|
|
|
199
203
|
### Fastify Plugins team
|
|
200
204
|
* [__Matteo Collina__](https://github.com/mcollina), <https://twitter.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
|
|
@@ -210,6 +214,13 @@ Great contributors on a specific area in the Fastify ecosystem will be invited t
|
|
|
210
214
|
**Past Collaborators**
|
|
211
215
|
* [__Çağatay Çalı__](https://github.com/cagataycali), <https://twitter.com/cagataycali>, <https://www.npmjs.com/~cagataycali>
|
|
212
216
|
* [__Trivikram Kamat__](https://github.com/trivikr), <https://twitter.com/trivikram>, <https://www.npmjs.com/~trivikr>
|
|
217
|
+
* [__Nathan Woltman__](https://github.com/nwoltman), <https://twitter.com/NathanWoltman>, <https://www.npmjs.com/~nwoltman>
|
|
218
|
+
|
|
219
|
+
## Hosted by
|
|
220
|
+
|
|
221
|
+
[<img src="https://github.com/openjs-foundation/cross-project-council/blob/master/logos/openjsf-color.png?raw=true" width="250px;"/>](https://openjsf.org/projects/#incubating)
|
|
222
|
+
|
|
223
|
+
We are currently an [incubated project](https://openjsf.org/blog/2019/11/20/web-framework-fastify-joins-openjs-foundation-as-an-incubating-project/) at the OpenJS Foundation.
|
|
213
224
|
|
|
214
225
|
## Acknowledgements
|
|
215
226
|
|
|
@@ -15,9 +15,12 @@ const ajv = new Ajv({
|
|
|
15
15
|
const defaultInitOptions = {
|
|
16
16
|
bodyLimit: 1024 * 1024, // 1 MiB
|
|
17
17
|
caseSensitive: true,
|
|
18
|
+
disableRequestLogging: false,
|
|
18
19
|
ignoreTrailingSlash: false,
|
|
19
20
|
maxParamLength: 100,
|
|
20
21
|
onProtoPoisoning: 'error',
|
|
22
|
+
// TODO v3: default should be 'error'
|
|
23
|
+
onConstructorPoisoning: 'ignore',
|
|
21
24
|
pluginTimeout: 10000,
|
|
22
25
|
requestIdHeader: 'request-id',
|
|
23
26
|
requestIdLogLabel: 'reqId'
|
|
@@ -62,8 +65,13 @@ const schema = {
|
|
|
62
65
|
then: { setDefaultValue: true }
|
|
63
66
|
},
|
|
64
67
|
ignoreTrailingSlash: { type: 'boolean', default: defaultInitOptions.ignoreTrailingSlash },
|
|
68
|
+
disableRequestLogging: {
|
|
69
|
+
type: 'boolean',
|
|
70
|
+
default: false
|
|
71
|
+
},
|
|
65
72
|
maxParamLength: { type: 'integer', default: defaultInitOptions.maxParamLength },
|
|
66
73
|
onProtoPoisoning: { type: 'string', default: defaultInitOptions.onProtoPoisoning },
|
|
74
|
+
onConstructorPoisoning: { type: 'string', default: defaultInitOptions.onConstructorPoisoning },
|
|
67
75
|
pluginTimeout: { type: 'integer', default: defaultInitOptions.pluginTimeout },
|
|
68
76
|
requestIdHeader: { type: 'string', default: defaultInitOptions.requestIdHeader },
|
|
69
77
|
requestIdLogLabel: { type: 'string', default: defaultInitOptions.requestIdLogLabel }
|
package/docs/Benchmarking.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<h1 align="center">Fastify</h1>
|
|
2
2
|
|
|
3
3
|
## Benchmarking
|
|
4
|
-
Benchmarking is important if you want to measure how a change can impact your application
|
|
4
|
+
Benchmarking is important if you want to measure how a change can impact the performance of your application. We provide a simple way to benchmark your application from the point of view of a user and contributor. The setup allows you to automate benchmarks in different branches and on different Node.js versions.
|
|
5
5
|
|
|
6
6
|
The modules we'll use:
|
|
7
7
|
- [Autocannon](https://github.com/mcollina/autocannon): A HTTP/1.1 benchmarking tool written in node.
|
|
8
8
|
- [Branch-comparer](https://github.com/StarpTech/branch-comparer): Checkout multiple git branches, execute scripts and log the results.
|
|
9
9
|
- [Concurrently](https://github.com/kimmobrunfeldt/concurrently): Run commands concurrently.
|
|
10
|
-
- [Npx](https://github.com/zkat/npx) NPM package runner - We using it to run scripts against different Node.js Versions and execute local binaries. Shipped with npm@5.2.0.
|
|
10
|
+
- [Npx](https://github.com/zkat/npx) NPM package runner - We are using it to run scripts against different Node.js Versions and to execute local binaries. Shipped with npm@5.2.0.
|
|
11
11
|
|
|
12
12
|
## Simple
|
|
13
13
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<h1 align="center">Fastify</h1>
|
|
2
2
|
|
|
3
|
-
## Content
|
|
3
|
+
## `Content-Type` Parser
|
|
4
4
|
Natively, Fastify only supports `'application/json'` and `'text/plain'` content types. The default charset is `utf-8`. If you need to support different content types, you can use the `addContentTypeParser` API. *The default JSON and/or plain text parser can be changed.*
|
|
5
5
|
|
|
6
|
-
As with the other APIs, `addContentTypeParser` is encapsulated in the scope in which it is declared. This means that if you declare it in the root scope it will be available everywhere, while if you declare it inside a
|
|
6
|
+
As with the other APIs, `addContentTypeParser` is encapsulated in the scope in which it is declared. This means that if you declare it in the root scope it will be available everywhere, while if you declare it inside a plugin it will be available only in that scope and its children.
|
|
7
7
|
|
|
8
|
-
Fastify adds
|
|
8
|
+
Fastify automatically adds the parsed request payload to the [Fastify request](https://github.com/fastify/fastify/blob/master/docs/Request.md) object which you can access with `request.body`.
|
|
9
9
|
|
|
10
10
|
### Usage
|
|
11
11
|
```js
|
|
@@ -14,13 +14,15 @@ fastify.addContentTypeParser('application/jsoff', function (req, done) {
|
|
|
14
14
|
done(err, body)
|
|
15
15
|
})
|
|
16
16
|
})
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
// Handle multiple content types with the same function
|
|
18
19
|
fastify.addContentTypeParser(['text/xml', 'application/xml'], function (req, done) {
|
|
19
20
|
xmlParser(req, function (err, body) {
|
|
20
21
|
done(err, body)
|
|
21
22
|
})
|
|
22
23
|
})
|
|
23
|
-
|
|
24
|
+
|
|
25
|
+
// Async is also supported in Node versions >= 8.0.0
|
|
24
26
|
fastify.addContentTypeParser('application/jsoff', async function (req) {
|
|
25
27
|
var res = await new Promise((resolve, reject) => resolve(req))
|
|
26
28
|
return res
|
|
@@ -32,13 +34,13 @@ You can also use the `hasContentTypeParser` API to find if a specific content ty
|
|
|
32
34
|
```js
|
|
33
35
|
if (!fastify.hasContentTypeParser('application/jsoff')){
|
|
34
36
|
fastify.addContentTypeParser('application/jsoff', function (req, done) {
|
|
35
|
-
//
|
|
37
|
+
// Code to parse request body/payload for the given content type
|
|
36
38
|
})
|
|
37
39
|
}
|
|
38
40
|
```
|
|
39
41
|
|
|
40
42
|
#### Body Parser
|
|
41
|
-
You can parse the body of
|
|
43
|
+
You can parse the body of a request in two ways. The first one is shown above: you add a custom content type parser and handle the request stream. In the second one, you should pass a `parseAs` option to the `addContentTypeParser` API, where you declare how you want to get the body. It could be of type `'string'` or `'buffer'`. If you use the `parseAs` option, Fastify will internally handle the stream and perform some checks, such as the [maximum size](https://github.com/fastify/fastify/blob/master/docs/Server.md#factory-body-limit) of the body and the content length. If the limit is exceeded the custom parser will not be invoked.
|
|
42
44
|
```js
|
|
43
45
|
fastify.addContentTypeParser('application/json', { parseAs: 'string' }, function (req, body, done) {
|
|
44
46
|
try {
|
|
@@ -58,8 +60,8 @@ See [`example/parser.js`](https://github.com/fastify/fastify/blob/master/example
|
|
|
58
60
|
+ `parseAs` (string): Either `'string'` or `'buffer'` to designate how the incoming data should be collected. Default: `'buffer'`.
|
|
59
61
|
+ `bodyLimit` (number): The maximum payload size, in bytes, that the custom parser will accept. Defaults to the global body limit passed to the [`Fastify factory function`](https://github.com/fastify/fastify/blob/master/docs/Server.md#bodylimit).
|
|
60
62
|
|
|
61
|
-
#### Catch
|
|
62
|
-
There are some cases where you need to catch all requests regardless of their content type. With Fastify, you just
|
|
63
|
+
#### Catch-All
|
|
64
|
+
There are some cases where you need to catch all requests regardless of their content type. With Fastify, you can just use the `'*'` content type.
|
|
63
65
|
```js
|
|
64
66
|
fastify.addContentTypeParser('*', function (req, done) {
|
|
65
67
|
var data = ''
|
|
@@ -70,7 +72,7 @@ fastify.addContentTypeParser('*', function (req, done) {
|
|
|
70
72
|
})
|
|
71
73
|
```
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
Using this, all requests that do not have a corresponding content type parser will be handled by the specified function.
|
|
74
76
|
|
|
75
77
|
This is also useful for piping the request stream. You can define a content parser like:
|
|
76
78
|
|
package/docs/Decorators.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## Decorators
|
|
4
4
|
|
|
5
|
-
If you need to add functionality to the Fastify instance, the `decorate` API is what you
|
|
5
|
+
If you need to add functionality to the Fastify instance, the `decorate` API is what you want.
|
|
6
6
|
|
|
7
|
-
The API allows you to add new properties to the Fastify instance.
|
|
7
|
+
The API allows you to add new properties to the Fastify instance. Possible values are not restricted by type and could be functions, objects or strings, for example.
|
|
8
8
|
|
|
9
9
|
<a name="usage"></a>
|
|
10
10
|
### Usage
|
|
@@ -13,11 +13,11 @@ The API allows you to add new properties to the Fastify instance. A value is not
|
|
|
13
13
|
Just call the `decorate` API and pass the name of the new property and its value.
|
|
14
14
|
```js
|
|
15
15
|
fastify.decorate('utility', () => {
|
|
16
|
-
//
|
|
16
|
+
// Something very useful
|
|
17
17
|
})
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
As
|
|
20
|
+
As mentioned above, you can also decorate the instance with non-function values:
|
|
21
21
|
```js
|
|
22
22
|
fastify.decorate('conf', {
|
|
23
23
|
db: 'some.db',
|
|
@@ -25,7 +25,7 @@ fastify.decorate('conf', {
|
|
|
25
25
|
})
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
Once
|
|
28
|
+
Once the instance was decorated, you can access the new value by using the name you passed as a parameter:
|
|
29
29
|
```js
|
|
30
30
|
fastify.utility()
|
|
31
31
|
|
|
@@ -34,14 +34,14 @@ console.log(fastify.conf.db)
|
|
|
34
34
|
|
|
35
35
|
<a name="decorate-reply"></a>
|
|
36
36
|
**decorateReply**
|
|
37
|
-
As the name suggests, this API
|
|
37
|
+
As the name suggests, this API can be used to add new methods to the `Reply` core object. Just call the `decorateReply` API and pass the name of the new property and its value:
|
|
38
38
|
```js
|
|
39
39
|
fastify.decorateReply('utility', function () {
|
|
40
|
-
//
|
|
40
|
+
// Something very useful
|
|
41
41
|
})
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
Note: using an arrow function will break the binding of `this` to the Fastify `
|
|
44
|
+
Note: using an arrow function will break the binding of `this` to the Fastify `Reply` instance.
|
|
45
45
|
|
|
46
46
|
<a name="decorate-request"></a>
|
|
47
47
|
**decorateRequest**
|
|
@@ -52,12 +52,12 @@ fastify.decorateRequest('utility', function () {
|
|
|
52
52
|
})
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
Note: using an arrow function will break the binding of `this` to the Fastify `
|
|
55
|
+
Note: using an arrow function will break the binding of `this` to the Fastify `Request` instance.
|
|
56
56
|
|
|
57
57
|
<a name="decorators-encapsulation"></a>
|
|
58
|
-
#### Decorators and
|
|
58
|
+
#### Decorators and Encapsulation
|
|
59
59
|
|
|
60
|
-
If you define a decorator (using decorate
|
|
60
|
+
If you define a decorator (using `decorate`, `decorateRequest` or `decorateReply`) with the same name more than once in the same **encapsulated** plugin, Fastify will throw an exception.
|
|
61
61
|
|
|
62
62
|
As an example, the following will throw:
|
|
63
63
|
|
|
@@ -65,7 +65,7 @@ As an example, the following will throw:
|
|
|
65
65
|
const server = require('fastify')()
|
|
66
66
|
|
|
67
67
|
server.decorateReply('view', function (template, args) {
|
|
68
|
-
// Amazing view rendering engine
|
|
68
|
+
// Amazing view rendering engine
|
|
69
69
|
})
|
|
70
70
|
|
|
71
71
|
server.get('/', (req, reply) => {
|
|
@@ -75,7 +75,7 @@ server.get('/', (req, reply) => {
|
|
|
75
75
|
// Somewhere else in our codebase, we define another
|
|
76
76
|
// view decorator. This throws.
|
|
77
77
|
server.decorateReply('view', function (template, args) {
|
|
78
|
-
//
|
|
78
|
+
// Another rendering engine
|
|
79
79
|
})
|
|
80
80
|
|
|
81
81
|
server.listen(3000)
|
|
@@ -96,7 +96,7 @@ server.register(async function (server, opts) {
|
|
|
96
96
|
// plugin. This will not throw as outside of this encapsulated
|
|
97
97
|
// plugin view is the old one, while inside it is the new one.
|
|
98
98
|
server.decorateReply('view', function (template, args) {
|
|
99
|
-
//
|
|
99
|
+
// Another rendering engine
|
|
100
100
|
})
|
|
101
101
|
|
|
102
102
|
server.get('/', (req, reply) => {
|
package/docs/Ecosystem.md
CHANGED
|
@@ -51,6 +51,8 @@ Plugins maintained by the fastify team are listed under [Core](#core) while plug
|
|
|
51
51
|
- [`fastify-405`](https://github.com/Eomm/fastify-405) Fastify plugin that adds 405 HTTP status to your routes
|
|
52
52
|
- [`fastify-amqp`](https://github.com/RafaelGSS/fastify-amqp) Fastify AMQP connection plugin, to use with RabbitMQ or another connector. Just a wrapper to [`amqplib`](https://github.com/squaremo/amqp.node).
|
|
53
53
|
- [`fastify-angular-universal`](https://github.com/exequiel09/fastify-angular-universal) Angular server-side rendering support using [`@angular/platform-server`](https://github.com/angular/angular/tree/master/packages/platform-server) for Fastify
|
|
54
|
+
- [`fastify-auth0-verify`](https://github.com/nearform/fastify-auth0-verify): Auth0 verification plugin for Fastify, internally uses [fastify-jwt](https://npm.im/fastify-jwt) and [jsonwebtoken](https://npm.im/jsonwebtoken).
|
|
55
|
+
- [`fastify-autocrud`](https://github.com/paranoiasystem/fastify-autocrud) Plugin for autogenerate CRUD routes as fast as possible.
|
|
54
56
|
- [`fastify-babel`](https://github.com/cfware/fastify-babel) Fastify plugin for development servers which require babel transformations of JavaScript sources.
|
|
55
57
|
- [`fastify-blipp`](https://github.com/PavelPolyakov/fastify-blipp) Prints your routes to the console, so you definitely know which endpoints are available.
|
|
56
58
|
- [`fastify-bookshelf`](https://github.com/butlerx/fastify-bookshelfjs) Fastify plugin to add [bookshelf.js](http://bookshelfjs.org/) orm support.
|
|
@@ -63,6 +65,7 @@ Plugins maintained by the fastify team are listed under [Core](#core) while plug
|
|
|
63
65
|
- [`fastify-decorators`](https://github.com/L2jLiga/fastify-decorators) Fastify plugin that provides the set of TypeScript decorators.
|
|
64
66
|
- [`fastify-dynamodb`](https://github.com/matrus2/fastify-dynamodb) AWS DynamoDB plugin for Fastify. It exposes [AWS.DynamoDB.DocumentClient()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html) object.
|
|
65
67
|
- [`fastify-error-page`](https://github.com/hemerajs/fastify-error-page) Fastify plugin to print errors in structured HTML to the browser.
|
|
68
|
+
- [`fastify-errors-properties`](https://github.com/ShogunPanda/fastify-errors-properties) A error handling plugin for Fastify that enables additional properties in errors.
|
|
66
69
|
- [`fastify-favicon`](https://github.com/smartiniOnGitHub/fastify-favicon) Fastify plugin to serve default favicon.
|
|
67
70
|
- [`fastify-feature-flags`](https://gitlab.com/m03geek/fastify-feature-flags) Fastify feature flags plugin with multiple providers support (e.g. env, [config](http://lorenwest.github.io/node-config/), [unleash](https://unleash.github.io/)).
|
|
68
71
|
- [`fastify-file-upload`](https://github.com/huangang/fastify-file-upload) Fastify plugin for uploading files.
|
|
@@ -74,6 +77,7 @@ Plugins maintained by the fastify team are listed under [Core](#core) while plug
|
|
|
74
77
|
- [`fastify-healthcheck`](https://github.com/smartiniOnGitHub/fastify-healthcheck) Fastify plugin to serve an health check route and a probe script.
|
|
75
78
|
- [`fastify-hemera`](https://github.com/hemerajs/fastify-hemera) Fastify Hemera plugin, for writing reliable & fault-tolerant microservices with [nats.io](https://nats.io/).
|
|
76
79
|
- [`fastify-http2https`](https://github.com/lolo32/fastify-http2https) Redirect HTTP requests to HTTPS, both using the same port number, or different response on HTTP and HTTPS.
|
|
80
|
+
- [`fastify-https-redirect`](https://github.com/tomsvogel/fastify-https-redirect) Fastify plugin for auto redirect from http to https
|
|
77
81
|
- [`fastify-http-client`](https://github.com/kenuyx/fastify-http-client) Plugin to send HTTP(s) requests. Built upon [urllib](https://github.com/node-modules/urllib).
|
|
78
82
|
- [`fastify-influxdb`](https://github.com/alex-ppg/fastify-influxdb) Fastify InfluxDB plugin connecting to an InfluxDB instance via the Influx default package.
|
|
79
83
|
- [`fastify-jwt-authz`](https://github.com/Ethan-Arrowood/fastify-jwt-authz) JWT user scope verifier.
|
|
@@ -87,8 +91,9 @@ Plugins maintained by the fastify team are listed under [Core](#core) while plug
|
|
|
87
91
|
- [`fastify-markdown`](https://github.com/freezestudio/fastify-markdown) Plugin to markdown support.
|
|
88
92
|
- [`fastify-metrics`](https://gitlab.com/m03geek/fastify-metrics) Plugin for exporting [Prometheus](https://prometheus.io) metrics.
|
|
89
93
|
- [`fastify-mongo-memory`](https://github.com/chapuletta/fastify-mongo-memory) Fastify MongoDB in Memory Plugin for testing support.
|
|
94
|
+
- [`fastify-mongoose-api`](https://github.com/jeka-kiselyov/fastify-mongoose-api) Fastify plugin to create REST API methods based on Mongoose MongoDB models.
|
|
90
95
|
- [`fastify-mongoose-driver`](https://github.com/alex-ppg/fastify-mongoose) Fastify Mongoose plugin that connects to a MongoDB via the Mongoose plugin with support for Models.
|
|
91
|
-
- [`fastify-multer`](https://github.com/fox1t/multer) Multer is a plugin for handling multipart/form-data, which is primarily used for uploading files.
|
|
96
|
+
- [`fastify-multer`](https://github.com/fox1t/fastify-multer) Multer is a plugin for handling multipart/form-data, which is primarily used for uploading files.
|
|
92
97
|
- [`fastify-nats`](https://github.com/mahmed8003/fastify-nats) Plugin to share [NATS](http://nats.io) client across Fastify.
|
|
93
98
|
- [`fastify-no-additional-properties`](https://github.com/greguz/fastify-no-additional-properties) Add `additionalProperties: false` by default to your JSON Schemas.
|
|
94
99
|
- [`fastify-no-icon`](https://github.com/jsumners/fastify-no-icon) Plugin to eliminate thrown errors for `/favicon.ico` requests.
|
|
@@ -98,6 +103,7 @@ Plugins maintained by the fastify team are listed under [Core](#core) while plug
|
|
|
98
103
|
- [`fastify-openapi-glue`](https://github.com/seriousme/fastify-openapi-glue) Glue for Open Api specifications in Fastify, autogenerates routes based on an Open Api Specification
|
|
99
104
|
- [`fastify-oracle`](https://github.com/cemremengu/fastify-oracle) Attaches an [`oracledb`](https://github.com/oracle/node-oracledb) connection pool to a Fastify server instance.
|
|
100
105
|
- [`fastify-orientdb`](https://github.com/mahmed8003/fastify-orientdb) Fastify OrientDB connection plugin, with which you can share the OrientDB connection across every part of your server.
|
|
106
|
+
- [`fastify-qs`](https://github.com/webdevium/fastify-qs) A plugin for Fastify that adds support for parsing URL query parameters with [qs](https://github.com/ljharb/qs).
|
|
101
107
|
- [`fastify-rbac`](https://gitlab.com/m03geek/fastify-rbac) Fastify role-based access control plugin.
|
|
102
108
|
- [`fastify-register-routes`](https://github.com/israeleriston/fastify-register-routes) Plugin to automatically load routes from a specified path and optionally limit loaded file names by a regular expression.
|
|
103
109
|
- [`fastify-response-time`](https://github.com/lolo32/fastify-response-time) Add `X-Response-Time` header at each request for Fastify, in milliseconds.
|
package/docs/Errors.md
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
<a name="error-handling"></a>
|
|
7
7
|
### Error Handling
|
|
8
8
|
|
|
9
|
-
Uncaught errors are likely to cause memory leaks, file descriptor leaks and other major production issues. [Domains](https://nodejs.org/en/docs/guides/domain-postmortem/) were introduced to try fixing this issue, but they did not. Given the fact that it is not possible to process all uncaught errors
|
|
9
|
+
Uncaught errors are likely to cause memory leaks, file descriptor leaks and other major production issues. [Domains](https://nodejs.org/en/docs/guides/domain-postmortem/) were introduced to try fixing this issue, but they did not. Given the fact that it is not possible to process all uncaught errors sensibly, the best way to deal with them at the moment is to [crash](https://nodejs.org/api/process.html#process_warning_using_uncaughtexception_correctly). In case of promises, make sure to [handle](https://nodejs.org/dist/latest-v8.x/docs/api/deprecations.html#deprecations_dep0018_unhandled_promise_rejections) errors [correctly](https://github.com/mcollina/make-promises-safe).
|
|
10
10
|
|
|
11
11
|
Fastify follows an all-or-nothing approach and aims to be lean and optimal as much as possible. Thus, the developer is responsible for making sure that the errors are handled properly. Most of the errors are usually a result of unexpected input data, so we recommend specifying a [JSON.schema validation](https://github.com/fastify/fastify/blob/master/docs/Validation-and-Serialization.md) for your input data.
|
|
12
12
|
|
|
13
|
-
Note that Fastify doesn't catch uncaught errors within callback
|
|
14
|
-
If routes are declared as `async` though - the error will safely be caught by the promise and routed to the default error handler of Fastify for a generic `Internal Server Error` response. For customizing this
|
|
13
|
+
Note that Fastify doesn't catch uncaught errors within callback-based routes for you, so any uncaught errors will result in a crash.
|
|
14
|
+
If routes are declared as `async` though - the error will safely be caught by the promise and routed to the default error handler of Fastify for a generic `Internal Server Error` response. For customizing this behaviour, you should use [setErrorHandler](https://github.com/fastify/fastify/blob/master/docs/Server.md#seterrorhandler).
|
|
15
15
|
|
|
16
16
|
<a name="fastify-error-codes"></a>
|
|
17
17
|
### Fastify Error Codes
|
|
@@ -24,7 +24,7 @@ The parser for this content type was already registered.
|
|
|
24
24
|
<a name="FST_ERR_CTP_INVALID_TYPE"></a>
|
|
25
25
|
#### FST_ERR_CTP_INVALID_TYPE
|
|
26
26
|
|
|
27
|
-
The
|
|
27
|
+
The `Content-Type` should be a string.
|
|
28
28
|
|
|
29
29
|
<a name="FST_ERR_CTP_EMPTY_TYPE"></a>
|
|
30
30
|
#### FST_ERR_CTP_EMPTY_TYPE
|
|
@@ -44,12 +44,12 @@ The provided parse type is not supported. Accepted values are `string` or `buffe
|
|
|
44
44
|
<a name="FST_ERR_CTP_BODY_TOO_LARGE"></a>
|
|
45
45
|
#### FST_ERR_CTP_BODY_TOO_LARGE
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
The request body is larger than the provided limit.
|
|
48
48
|
|
|
49
49
|
<a name="FST_ERR_CTP_INVALID_MEDIA_TYPE"></a>
|
|
50
50
|
#### FST_ERR_CTP_INVALID_MEDIA_TYPE
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
The received media type is not supported (i.e. there is no suitable `Content-Type` parser for it).
|
|
53
53
|
|
|
54
54
|
<a name="FST_ERR_CTP_INVALID_CONTENT_LENGTH"></a>
|
|
55
55
|
#### FST_ERR_CTP_INVALID_CONTENT_LENGTH
|
|
@@ -79,7 +79,7 @@ The hook callback must be a function.
|
|
|
79
79
|
<a name="FST_ERR_LOG_INVALID_DESTINATION"></a>
|
|
80
80
|
#### FST_ERR_LOG_INVALID_DESTINATION
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
The logger accepts either a `'stream'` or a `'file'` as the destination.
|
|
83
83
|
|
|
84
84
|
<a id="FST_ERR_REP_ALREADY_SENT"></a>
|
|
85
85
|
### FST_ERR_REP_ALREADY_SENT
|
|
@@ -111,7 +111,12 @@ A schema with the same `$id` already exists.
|
|
|
111
111
|
|
|
112
112
|
No schema with the provided `$id` exists.
|
|
113
113
|
|
|
114
|
+
<a name="FST_ERR_SCH_BUILD"></a>
|
|
115
|
+
#### FST_ERR_SCH_BUILD
|
|
116
|
+
|
|
117
|
+
The JSON schema provided to one route is not valid.
|
|
118
|
+
|
|
114
119
|
<a name="FST_ERR_PROMISE_NOT_FULLFILLED"></a>
|
|
115
120
|
#### FST_ERR_PROMISE_NOT_FULLFILLED
|
|
116
121
|
|
|
117
|
-
|
|
122
|
+
A promise may not be fulfilled with 'undefined' when statusCode is not 204.
|
package/docs/Fluent-Schema.md
CHANGED
|
@@ -2,19 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## Fluent Schema
|
|
4
4
|
|
|
5
|
-
The [Validation and Serialization](https://github.com/fastify/fastify/blob/master/docs/Validation-and-Serialization.md)
|
|
6
|
-
has explained all the parameter accepted by Fastify to set a JSON Schema Validation, to validates
|
|
7
|
-
the input, and a JSON Schema Serialization to optimize the output.
|
|
5
|
+
The [Validation and Serialization](https://github.com/fastify/fastify/blob/master/docs/Validation-and-Serialization.md) documentation outlines all parameters accepted by Fastify to set up JSON Schema Validation in order to validate the input, and JSON Schema Serialization in order to optimize the output.
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
to simplify this task and reuse constants values.
|
|
7
|
+
[`fluent-schema`](fluent-schema-repo) can be used to simplify this task while allowing the reuse of constants.
|
|
11
8
|
|
|
12
9
|
### Basic settings
|
|
13
10
|
|
|
14
11
|
```js
|
|
15
12
|
const S = require('fluent-schema')
|
|
16
13
|
|
|
17
|
-
// You can have an object like this, or query a
|
|
14
|
+
// You can have an object like this, or query a DB to get the values
|
|
18
15
|
const MY_KEY = {
|
|
19
16
|
KEY1: 'ONE',
|
|
20
17
|
KEY2: 'TWO'
|
|
@@ -41,7 +38,7 @@ const paramsJsonSchema = S.object()
|
|
|
41
38
|
const headersJsonSchema = S.object()
|
|
42
39
|
.prop('x-foo', S.string().required())
|
|
43
40
|
|
|
44
|
-
//
|
|
41
|
+
// Note that there is no need to call `.valueOf()`!
|
|
45
42
|
const schema = {
|
|
46
43
|
body: bodyJsonSchema,
|
|
47
44
|
querystring: queryStringJsonSchema, // (or) query: queryStringJsonSchema
|
|
@@ -56,11 +53,11 @@ fastify.post('/the/url', { schema }, handler)
|
|
|
56
53
|
|
|
57
54
|
With `fluent-schema` you can manipulate your schemas in an easier and programmatic way and then reuse them
|
|
58
55
|
thanks to the `addSchema()` method. You can refer to the schema in two different manners that are detailed
|
|
59
|
-
in [Validation-and-Serialization.md](./Validation-and-Serialization.md#adding-a-shared-schema)
|
|
56
|
+
in the [Validation-and-Serialization.md](./Validation-and-Serialization.md#adding-a-shared-schema) documentation.
|
|
60
57
|
|
|
61
|
-
Here some
|
|
58
|
+
Here are some usage examples:
|
|
62
59
|
|
|
63
|
-
**`$ref-way`**: refer to external schema.
|
|
60
|
+
**`$ref-way`**: refer to an external schema.
|
|
64
61
|
|
|
65
62
|
```js
|
|
66
63
|
const addressSchema = S.object()
|
|
@@ -74,7 +71,7 @@ const addressSchema = S.object()
|
|
|
74
71
|
const commonSchemas = S.object()
|
|
75
72
|
.id('https://fastify/demo')
|
|
76
73
|
.definition('addressSchema', addressSchema)
|
|
77
|
-
.definition('otherSchema', otherSchema) //
|
|
74
|
+
.definition('otherSchema', otherSchema) // You can add any schemas you need
|
|
78
75
|
|
|
79
76
|
fastify.addSchema(commonSchemas)
|
|
80
77
|
|
|
@@ -117,6 +114,6 @@ const schema = { body: bodyJsonSchema }
|
|
|
117
114
|
fastify.post('/the/url', { schema }, handler)
|
|
118
115
|
```
|
|
119
116
|
|
|
120
|
-
NB: you can mix up the
|
|
117
|
+
NB: you can mix up the `$ref-way` and the `replace-way` when using `fastify.addSchema`.
|
|
121
118
|
|
|
122
119
|
[fluent-schema-repo]: https://github.com/fastify/fluent-schema
|
package/docs/Getting-Started.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Getting Started
|
|
4
4
|
Hello! Thank you for checking out Fastify!<br>
|
|
5
|
-
This document aims to be a gentle introduction to the framework and its features. It is an elementary
|
|
5
|
+
This document aims to be a gentle introduction to the framework and its features. It is an elementary preface with examples and links to other parts of the documentation.<br>
|
|
6
6
|
Let's start!
|
|
7
7
|
|
|
8
8
|
<a name="install"></a>
|
|
@@ -41,7 +41,7 @@ fastify.listen(3000, function (err, address) {
|
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
Do you prefer to use `async/await`? Fastify supports it out-of-the-box.<br>
|
|
44
|
-
*(
|
|
44
|
+
*(We also suggest using [make-promises-safe](https://github.com/mcollina/make-promises-safe) to avoid file descriptor and memory leaks.)*
|
|
45
45
|
```js
|
|
46
46
|
const fastify = require('fastify')()
|
|
47
47
|
|
|
@@ -61,8 +61,8 @@ start()
|
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
Awesome, that was easy.<br>
|
|
64
|
-
Unfortunately, writing a complex application requires significantly more code than this example. A classic problem when you are building a new application is how handle multiple files, asynchronous bootstrapping and the architecture of your code.<br>
|
|
65
|
-
Fastify offers an easy platform that helps solve all of problems, and more
|
|
64
|
+
Unfortunately, writing a complex application requires significantly more code than this example. A classic problem when you are building a new application is how to handle multiple files, asynchronous bootstrapping and the architecture of your code.<br>
|
|
65
|
+
Fastify offers an easy platform that helps to solve all of the problems outlined above, and more!
|
|
66
66
|
|
|
67
67
|
> ## Note
|
|
68
68
|
> The above examples, and subsequent examples in this document, default to listening *only* on the localhost `127.0.0.1` interface. To listen on all available IPv4 interfaces the example should be modified to listen on `0.0.0.0` like so:
|
|
@@ -83,9 +83,9 @@ Fastify offers an easy platform that helps solve all of problems, and more.
|
|
|
83
83
|
|
|
84
84
|
<a name="first-plugin"></a>
|
|
85
85
|
### Your first plugin
|
|
86
|
-
As with JavaScript everything is an object, with Fastify everything is a plugin.<br>
|
|
86
|
+
As with JavaScript, where everything is an object, with Fastify everything is a plugin.<br>
|
|
87
87
|
Before digging into it, let's see how it works!<br>
|
|
88
|
-
Let's declare our basic server, but instead of declaring the route inside the entry point, we'll declare it in an external file (
|
|
88
|
+
Let's declare our basic server, but instead of declaring the route inside the entry point, we'll declare it in an external file (check out the [route declaration](https://github.com/fastify/fastify/blob/master/docs/Routes.md) docs).
|
|
89
89
|
```js
|
|
90
90
|
const fastify = require('fastify')({
|
|
91
91
|
logger: true
|
|
@@ -113,16 +113,22 @@ async function routes (fastify, options) {
|
|
|
113
113
|
|
|
114
114
|
module.exports = routes
|
|
115
115
|
```
|
|
116
|
-
In this example we used the `register` API
|
|
116
|
+
In this example, we used the `register` API, which is the core of the Fastify framework. It is the only way to add routes, plugins, et cetera.
|
|
117
117
|
|
|
118
|
-
At the beginning of this guide we noted that Fastify provides a foundation that assists with
|
|
119
|
-
Consider the scenario where a database connection is needed to handle data storage. Obviously the database connection needs to be available
|
|
120
|
-
A typical solution is to use a complex callback, or promises
|
|
118
|
+
At the beginning of this guide, we noted that Fastify provides a foundation that assists with asynchronous bootstrapping of your application. Why is this important?
|
|
119
|
+
Consider the scenario where a database connection is needed to handle data storage. Obviously, the database connection needs to be available before the server is accepting connections. How do we address this problem?<br>
|
|
120
|
+
A typical solution is to use a complex callback, or promises - a system that will mix the framework API with other libraries and the application code.<br>
|
|
121
121
|
Fastify handles this internally, with minimum effort!
|
|
122
122
|
|
|
123
123
|
Let's rewrite the above example with a database connection.<br>
|
|
124
124
|
*(we will use a simple example, for a robust solution consider using [`fastify-mongo`](https://github.com/fastify/fastify-mongodb) or another in the Fastify [ecosystem](https://github.com/fastify/fastify/blob/master/docs/Ecosystem.md))*
|
|
125
125
|
|
|
126
|
+
First, install `fastify-plugin`:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
npm install --save fastify-plugin
|
|
130
|
+
```
|
|
131
|
+
|
|
126
132
|
**server.js**
|
|
127
133
|
```js
|
|
128
134
|
const fastify = require('fastify')({
|
|
@@ -185,18 +191,17 @@ module.exports = routes
|
|
|
185
191
|
|
|
186
192
|
Wow, that was fast!<br>
|
|
187
193
|
Let's recap what we have done here since we've introduced some new concepts.<br>
|
|
188
|
-
As you can see, we used `register` both for the database connector and the routes
|
|
189
|
-
This is one of the best features of Fastify, it will load your plugins in the same order you declare them, and it will load the next plugin only once the current one has been loaded. In this way we can register the database connector in the first plugin and use it in the second *(read [here](https://github.com/fastify/fastify/blob/master/docs/Plugins.md#handle-the-scope) to understand how to handle the scope of a plugin)*.
|
|
194
|
+
As you can see, we used `register` both for the database connector and the registration of the routes.
|
|
195
|
+
This is one of the best features of Fastify, it will load your plugins in the same order you declare them, and it will load the next plugin only once the current one has been loaded. In this way, we can register the database connector in the first plugin and use it in the second *(read [here](https://github.com/fastify/fastify/blob/master/docs/Plugins.md#handle-the-scope) to understand how to handle the scope of a plugin)*.
|
|
190
196
|
Plugin loading starts when you call `fastify.listen()`, `fastify.inject()` or `fastify.ready()`
|
|
191
197
|
|
|
192
|
-
We have used the `decorate` API
|
|
193
|
-
To solve this Fastify offers the `decorate` API, which adds custom objects to the Fastify namespace, so that they can be used everywhere.
|
|
198
|
+
We have also used the `decorate` API to add custom objects to the Fastify namespace, making them available for use everywhere. Use of this API is encouraged to faciliate easy code reuse and to decrease code or logic duplication.
|
|
194
199
|
|
|
195
200
|
To dig deeper into how Fastify plugins work, how to develop new plugins, and for details on how to use the whole Fastify API to deal with the complexity of asynchronously bootstrapping an application, read [the hitchhiker's guide to plugins](https://github.com/fastify/fastify/blob/master/docs/Plugins-Guide.md).
|
|
196
201
|
|
|
197
202
|
<a name="plugin-loading-order"></a>
|
|
198
203
|
### Loading order of your plugins
|
|
199
|
-
To guarantee a consistent and predictable
|
|
204
|
+
To guarantee a consistent and predictable behaviour of your application, we highly recommend to always load your code as shown below:
|
|
200
205
|
```
|
|
201
206
|
└── plugins (from the Fastify ecosystem)
|
|
202
207
|
└── your plugins (your custom plugins)
|
|
@@ -204,8 +209,8 @@ To guarantee a consistent and predictable behavior of your application, we highl
|
|
|
204
209
|
└── hooks and middlewares
|
|
205
210
|
└── your services
|
|
206
211
|
```
|
|
207
|
-
In this way you will always have access to all of the properties declared in the current scope.<br/>
|
|
208
|
-
As discussed previously, Fastify offers a solid encapsulation model, to help you build your application as single and independent services. If you want to register a plugin only for a subset of routes, you have
|
|
212
|
+
In this way, you will always have access to all of the properties declared in the current scope.<br/>
|
|
213
|
+
As discussed previously, Fastify offers a solid encapsulation model, to help you build your application as single and independent services. If you want to register a plugin only for a subset of routes, you just have to replicate the above structure.
|
|
209
214
|
```
|
|
210
215
|
└── plugins (from the Fastify ecosystem)
|
|
211
216
|
└── your plugins (your custom plugins)
|
|
@@ -230,7 +235,7 @@ As discussed previously, Fastify offers a solid encapsulation model, to help you
|
|
|
230
235
|
|
|
231
236
|
<a name="validate-data"></a>
|
|
232
237
|
### Validate your data
|
|
233
|
-
Data validation is extremely important and
|
|
238
|
+
Data validation is extremely important and a core concept of the framework.<br>
|
|
234
239
|
To validate incoming requests, Fastify uses [JSON Schema](http://json-schema.org/).
|
|
235
240
|
Let's look at an example demonstrating validation for routes:
|
|
236
241
|
```js
|
|
@@ -255,8 +260,8 @@ Read [Validation and Serialization](https://github.com/fastify/fastify/blob/mast
|
|
|
255
260
|
|
|
256
261
|
<a name="serialize-data"></a>
|
|
257
262
|
### Serialize your data
|
|
258
|
-
Fastify has first class support for JSON. It is extremely optimized to parse
|
|
259
|
-
To speed up JSON serialization (yes, it is slow!) use the `response` key of the schema option
|
|
263
|
+
Fastify has first class support for JSON. It is extremely optimized to parse JSON bodies and to serialize JSON output.<br>
|
|
264
|
+
To speed up JSON serialization (yes, it is slow!) use the `response` key of the schema option as shown in the following example:
|
|
260
265
|
```js
|
|
261
266
|
const opts = {
|
|
262
267
|
schema: {
|
|
@@ -275,23 +280,22 @@ fastify.get('/', opts, async (request, reply) => {
|
|
|
275
280
|
return { hello: 'world' }
|
|
276
281
|
})
|
|
277
282
|
```
|
|
278
|
-
Simply by specifying a schema as shown,
|
|
283
|
+
Simply by specifying a schema as shown, you can speed up serialization by a factor of 2-3. This also helps to protect against leakage of potentially sensitive data, since Fastify will serialize only the data present in the response schema.
|
|
279
284
|
Read [Validation and Serialization](https://github.com/fastify/fastify/blob/master/docs/Validation-and-Serialization.md) to learn more.
|
|
280
285
|
|
|
281
286
|
<a name="extend-server"></a>
|
|
282
287
|
### Extend your server
|
|
283
|
-
Fastify is built to be extremely extensible and
|
|
288
|
+
Fastify is built to be extremely extensible and minimal, we believe that a bare bones framework is all that is necessary to make great applications possible.<br>
|
|
284
289
|
In other words, Fastify is not a "batteries included" framework, and relies on an amazing [ecosystem](https://github.com/fastify/fastify/blob/master/docs/Ecosystem.md)!
|
|
285
290
|
|
|
286
291
|
<a name="test-server"></a>
|
|
287
292
|
### Test your server
|
|
288
|
-
Fastify does not offer a testing framework, but we do recommend a way to write your tests that uses the features and
|
|
293
|
+
Fastify does not offer a testing framework, but we do recommend a way to write your tests that uses the features and architecture of Fastify.<br>
|
|
289
294
|
Read the [testing](https://github.com/fastify/fastify/blob/master/docs/Testing.md) documentation to learn more!
|
|
290
295
|
|
|
291
296
|
<a name="cli"></a>
|
|
292
297
|
### Run your server from CLI
|
|
293
|
-
Fastify also has CLI integration thanks to
|
|
294
|
-
[fastify-cli](https://github.com/fastify/fastify-cli).
|
|
298
|
+
Fastify also has CLI integration thanks to [fastify-cli](https://github.com/fastify/fastify-cli).
|
|
295
299
|
|
|
296
300
|
First, install `fastify-cli`:
|
|
297
301
|
|
package/docs/HTTP2.md
CHANGED
|
@@ -35,7 +35,7 @@ fastify.get('/', function (request, reply) {
|
|
|
35
35
|
fastify.listen(3000)
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
ALPN negotiation allows
|
|
38
|
+
ALPN negotiation allows support for both HTTPS and HTTP/2 over the same socket.
|
|
39
39
|
Node core `req` and `res` objects can be either [HTTP/1](https://nodejs.org/api/http.html)
|
|
40
40
|
or [HTTP/2](https://nodejs.org/api/http2.html).
|
|
41
41
|
_Fastify_ supports this out of the box:
|