fastify 4.0.0-alpha.1 → 4.0.0-alpha.2
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/.taprc +3 -0
- package/README.md +2 -3
- package/docs/Guides/Database.md +320 -0
- package/docs/Guides/Getting-Started.md +7 -7
- package/docs/Guides/Plugins-Guide.md +1 -1
- package/docs/Guides/Serverless.md +3 -3
- package/docs/Guides/Testing.md +2 -2
- package/docs/Reference/Decorators.md +2 -2
- package/docs/Reference/Encapsulation.md +2 -2
- package/docs/Reference/HTTP2.md +3 -3
- package/docs/Reference/Plugins.md +3 -3
- package/docs/Reference/Routes.md +5 -5
- package/docs/Reference/Server.md +27 -62
- package/docs/Reference/TypeScript.md +9 -9
- package/docs/Reference/Validation-and-Serialization.md +4 -4
- package/docs/Type-Providers.md +2 -2
- package/examples/asyncawait.js +1 -1
- package/examples/benchmark/hooks-benchmark-async-await.js +1 -1
- package/examples/benchmark/hooks-benchmark.js +1 -1
- package/examples/benchmark/simple.js +1 -1
- package/examples/hooks.js +1 -1
- package/examples/http2.js +1 -1
- package/examples/https.js +1 -1
- package/examples/parser.js +1 -1
- package/examples/route-prefix.js +1 -1
- package/examples/shared-schema.js +1 -1
- package/examples/simple-stream.js +1 -1
- package/examples/simple.js +1 -1
- package/examples/simple.mjs +1 -1
- package/examples/typescript-server.ts +1 -1
- package/examples/use-plugin.js +1 -1
- package/fastify.js +4 -2
- package/lib/reply.js +1 -1
- package/lib/server.js +32 -10
- package/lib/warnings.js +2 -0
- package/package.json +13 -11
- package/test/404s.test.js +16 -16
- package/test/500s.test.js +1 -1
- package/test/als.test.js +1 -1
- package/test/async-await.test.js +7 -7
- package/test/bodyLimit.test.js +1 -1
- package/test/build-certificate.js +6 -7
- package/test/case-insensitive.test.js +4 -4
- package/test/close-pipelining.test.js +2 -2
- package/test/close.test.js +11 -11
- package/test/custom-http-server.test.js +1 -1
- package/test/custom-parser-async.test.js +1 -1
- package/test/custom-parser.test.js +38 -38
- package/test/custom-querystring-parser.test.js +3 -3
- package/test/decorator.test.js +10 -10
- package/test/delete.test.js +1 -1
- package/test/genReqId.test.js +1 -1
- package/test/get.test.js +1 -1
- package/test/handler-context.test.js +2 -2
- package/test/head.test.js +1 -1
- package/test/helper.js +1 -1
- package/test/hooks-async.test.js +1 -1
- package/test/hooks.on-ready.test.js +1 -1
- package/test/hooks.test.js +20 -20
- package/test/http2/closing.test.js +5 -5
- package/test/http2/constraint.test.js +1 -1
- package/test/http2/head.test.js +1 -1
- package/test/http2/plain.test.js +1 -1
- package/test/http2/secure-with-fallback.test.js +1 -1
- package/test/http2/secure.test.js +1 -1
- package/test/http2/unknown-http-method.test.js +1 -1
- package/test/https/custom-https-server.test.js +1 -1
- package/test/https/https.test.js +1 -1
- package/test/input-validation.js +1 -1
- package/test/internals/handleRequest.test.js +3 -3
- package/test/internals/initialConfig.test.js +9 -1
- package/test/internals/logger.test.js +2 -2
- package/test/internals/reply.test.js +41 -42
- package/test/internals/server.test.js +5 -5
- package/test/listen.deprecated.test.js +202 -0
- package/test/listen.test.js +41 -156
- package/test/logger.test.js +15 -15
- package/test/maxRequestsPerSocket.test.js +2 -2
- package/test/nullable-validation.test.js +3 -3
- package/test/output-validation.test.js +1 -1
- package/test/plugin.test.js +16 -16
- package/test/promises.test.js +1 -1
- package/test/proto-poisoning.test.js +6 -6
- package/test/register.test.js +3 -3
- package/test/reply-error.test.js +3 -3
- package/test/request-error.test.js +1 -1
- package/test/route-hooks.test.js +1 -1
- package/test/route.test.js +3 -3
- package/test/router-options.test.js +1 -1
- package/test/schema-feature.test.js +1 -1
- package/test/schema-special-usage.test.js +0 -81
- package/test/skip-reply-send.test.js +1 -1
- package/test/stream.test.js +60 -12
- package/test/trust-proxy.test.js +6 -6
- package/test/types/instance.test-d.ts +33 -3
- package/test/types/reply.test-d.ts +2 -1
- package/test/url-rewriting.test.js +3 -3
- package/test/versioned-routes.test.js +3 -3
- package/types/.eslintrc.json +3 -1
- package/types/instance.d.ts +120 -14
- package/types/reply.d.ts +2 -1
package/test/404s.test.js
CHANGED
|
@@ -30,7 +30,7 @@ test('default 404', t => {
|
|
|
30
30
|
|
|
31
31
|
t.teardown(fastify.close.bind(fastify))
|
|
32
32
|
|
|
33
|
-
fastify.listen(0, err => {
|
|
33
|
+
fastify.listen({ port: 0 }, err => {
|
|
34
34
|
t.error(err)
|
|
35
35
|
|
|
36
36
|
test('unsupported method', t => {
|
|
@@ -104,7 +104,7 @@ test('customized 404', t => {
|
|
|
104
104
|
|
|
105
105
|
t.teardown(fastify.close.bind(fastify))
|
|
106
106
|
|
|
107
|
-
fastify.listen(0, err => {
|
|
107
|
+
fastify.listen({ port: 0 }, err => {
|
|
108
108
|
t.error(err)
|
|
109
109
|
|
|
110
110
|
test('unsupported method', t => {
|
|
@@ -194,7 +194,7 @@ test('custom header in notFound handler', t => {
|
|
|
194
194
|
|
|
195
195
|
t.teardown(fastify.close.bind(fastify))
|
|
196
196
|
|
|
197
|
-
fastify.listen(0, err => {
|
|
197
|
+
fastify.listen({ port: 0 }, err => {
|
|
198
198
|
t.error(err)
|
|
199
199
|
|
|
200
200
|
test('not found with custom header', t => {
|
|
@@ -250,7 +250,7 @@ test('setting a custom 404 handler multiple times is an error', t => {
|
|
|
250
250
|
done()
|
|
251
251
|
}, { prefix: '/prefix' })
|
|
252
252
|
|
|
253
|
-
fastify.listen(0, err => {
|
|
253
|
+
fastify.listen({ port: 0 }, err => {
|
|
254
254
|
t.error(err)
|
|
255
255
|
fastify.close()
|
|
256
256
|
})
|
|
@@ -274,7 +274,7 @@ test('setting a custom 404 handler multiple times is an error', t => {
|
|
|
274
274
|
|
|
275
275
|
fastify.setNotFoundHandler(() => {})
|
|
276
276
|
|
|
277
|
-
fastify.listen(0, err => {
|
|
277
|
+
fastify.listen({ port: 0 }, err => {
|
|
278
278
|
t.error(err)
|
|
279
279
|
fastify.close()
|
|
280
280
|
})
|
|
@@ -304,7 +304,7 @@ test('setting a custom 404 handler multiple times is an error', t => {
|
|
|
304
304
|
|
|
305
305
|
fastify.setNotFoundHandler(() => {})
|
|
306
306
|
|
|
307
|
-
fastify.listen(0, err => {
|
|
307
|
+
fastify.listen({ port: 0 }, err => {
|
|
308
308
|
t.error(err)
|
|
309
309
|
fastify.close()
|
|
310
310
|
})
|
|
@@ -337,7 +337,7 @@ test('setting a custom 404 handler multiple times is an error', t => {
|
|
|
337
337
|
|
|
338
338
|
fastify.setNotFoundHandler(() => {})
|
|
339
339
|
|
|
340
|
-
fastify.listen(0, err => {
|
|
340
|
+
fastify.listen({ port: 0 }, err => {
|
|
341
341
|
t.error(err)
|
|
342
342
|
fastify.close()
|
|
343
343
|
})
|
|
@@ -381,7 +381,7 @@ test('encapsulated 404', t => {
|
|
|
381
381
|
|
|
382
382
|
t.teardown(fastify.close.bind(fastify))
|
|
383
383
|
|
|
384
|
-
fastify.listen(0, err => {
|
|
384
|
+
fastify.listen({ port: 0 }, err => {
|
|
385
385
|
t.error(err)
|
|
386
386
|
|
|
387
387
|
test('root unsupported method', t => {
|
|
@@ -695,7 +695,7 @@ test('run hooks on default 404', t => {
|
|
|
695
695
|
|
|
696
696
|
t.teardown(fastify.close.bind(fastify))
|
|
697
697
|
|
|
698
|
-
fastify.listen(0, err => {
|
|
698
|
+
fastify.listen({ port: 0 }, err => {
|
|
699
699
|
t.error(err)
|
|
700
700
|
|
|
701
701
|
sget({
|
|
@@ -856,7 +856,7 @@ test('run hook with encapsulated 404', t => {
|
|
|
856
856
|
|
|
857
857
|
t.teardown(fastify.close.bind(fastify))
|
|
858
858
|
|
|
859
|
-
fastify.listen(0, err => {
|
|
859
|
+
fastify.listen({ port: 0 }, err => {
|
|
860
860
|
t.error(err)
|
|
861
861
|
|
|
862
862
|
sget({
|
|
@@ -926,7 +926,7 @@ test('run hook with encapsulated 404 and framework-unsupported method', t => {
|
|
|
926
926
|
|
|
927
927
|
t.teardown(fastify.close.bind(fastify))
|
|
928
928
|
|
|
929
|
-
fastify.listen(0, err => {
|
|
929
|
+
fastify.listen({ port: 0 }, err => {
|
|
930
930
|
t.error(err)
|
|
931
931
|
|
|
932
932
|
sget({
|
|
@@ -966,7 +966,7 @@ test('hooks check 404', t => {
|
|
|
966
966
|
|
|
967
967
|
t.teardown(fastify.close.bind(fastify))
|
|
968
968
|
|
|
969
|
-
fastify.listen(0, err => {
|
|
969
|
+
fastify.listen({ port: 0 }, err => {
|
|
970
970
|
t.error(err)
|
|
971
971
|
|
|
972
972
|
sget({
|
|
@@ -1066,7 +1066,7 @@ test('Unknown method', t => {
|
|
|
1066
1066
|
|
|
1067
1067
|
t.teardown(fastify.close.bind(fastify))
|
|
1068
1068
|
|
|
1069
|
-
fastify.listen(0, err => {
|
|
1069
|
+
fastify.listen({ port: 0 }, err => {
|
|
1070
1070
|
t.error(err)
|
|
1071
1071
|
|
|
1072
1072
|
const handler = () => {}
|
|
@@ -1102,7 +1102,7 @@ test('recognizes errors from the http-errors module', t => {
|
|
|
1102
1102
|
|
|
1103
1103
|
t.teardown(fastify.close.bind(fastify))
|
|
1104
1104
|
|
|
1105
|
-
fastify.listen(0, err => {
|
|
1105
|
+
fastify.listen({ port: 0 }, err => {
|
|
1106
1106
|
t.error(err)
|
|
1107
1107
|
|
|
1108
1108
|
fastify.inject({
|
|
@@ -1220,7 +1220,7 @@ test('cannot set notFoundHandler after binding', t => {
|
|
|
1220
1220
|
const fastify = Fastify()
|
|
1221
1221
|
t.teardown(fastify.close.bind(fastify))
|
|
1222
1222
|
|
|
1223
|
-
fastify.listen(0, err => {
|
|
1223
|
+
fastify.listen({ port: 0 }, err => {
|
|
1224
1224
|
t.error(err)
|
|
1225
1225
|
|
|
1226
1226
|
try {
|
|
@@ -1254,7 +1254,7 @@ test('404 inside onSend', t => {
|
|
|
1254
1254
|
|
|
1255
1255
|
t.teardown(fastify.close.bind(fastify))
|
|
1256
1256
|
|
|
1257
|
-
fastify.listen(0, err => {
|
|
1257
|
+
fastify.listen({ port: 0 }, err => {
|
|
1258
1258
|
t.error(err)
|
|
1259
1259
|
|
|
1260
1260
|
sget({
|
package/test/500s.test.js
CHANGED
package/test/als.test.js
CHANGED
package/test/async-await.test.js
CHANGED
|
@@ -46,7 +46,7 @@ test('async await', t => {
|
|
|
46
46
|
t.fail()
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
fastify.listen(0, err => {
|
|
49
|
+
fastify.listen({ port: 0 }, err => {
|
|
50
50
|
t.error(err)
|
|
51
51
|
fastify.server.unref()
|
|
52
52
|
|
|
@@ -84,7 +84,7 @@ test('ignore the result of the promise if reply.send is called beforehand (undef
|
|
|
84
84
|
|
|
85
85
|
t.teardown(server.close.bind(server))
|
|
86
86
|
|
|
87
|
-
server.listen(0, (err) => {
|
|
87
|
+
server.listen({ port: 0 }, (err) => {
|
|
88
88
|
t.error(err)
|
|
89
89
|
sget({
|
|
90
90
|
method: 'GET',
|
|
@@ -110,7 +110,7 @@ test('ignore the result of the promise if reply.send is called beforehand (objec
|
|
|
110
110
|
|
|
111
111
|
t.teardown(server.close.bind(server))
|
|
112
112
|
|
|
113
|
-
server.listen(0, (err) => {
|
|
113
|
+
server.listen({ port: 0 }, (err) => {
|
|
114
114
|
t.error(err)
|
|
115
115
|
sget({
|
|
116
116
|
method: 'GET',
|
|
@@ -165,7 +165,7 @@ test('ignore the result of the promise if reply.send is called beforehand (undef
|
|
|
165
165
|
|
|
166
166
|
t.teardown(server.close.bind(server))
|
|
167
167
|
|
|
168
|
-
server.listen(0, (err) => {
|
|
168
|
+
server.listen({ port: 0 }, (err) => {
|
|
169
169
|
t.error(err)
|
|
170
170
|
sget({
|
|
171
171
|
method: 'GET',
|
|
@@ -191,7 +191,7 @@ test('ignore the result of the promise if reply.send is called beforehand (objec
|
|
|
191
191
|
|
|
192
192
|
t.teardown(server.close.bind(server))
|
|
193
193
|
|
|
194
|
-
server.listen(0, (err) => {
|
|
194
|
+
server.listen({ port: 0 }, (err) => {
|
|
195
195
|
t.error(err)
|
|
196
196
|
sget({
|
|
197
197
|
method: 'GET',
|
|
@@ -408,7 +408,7 @@ test('promise was fulfilled with undefined', t => {
|
|
|
408
408
|
t.fail('should not log an error')
|
|
409
409
|
})
|
|
410
410
|
|
|
411
|
-
fastify.listen(0, (err) => {
|
|
411
|
+
fastify.listen({ port: 0 }, (err) => {
|
|
412
412
|
t.error(err)
|
|
413
413
|
fastify.server.unref()
|
|
414
414
|
|
|
@@ -450,7 +450,7 @@ test('error is not logged because promise was fulfilled with undefined but respo
|
|
|
450
450
|
t.fail('should not log an error')
|
|
451
451
|
})
|
|
452
452
|
|
|
453
|
-
fastify.listen(0, (err) => {
|
|
453
|
+
fastify.listen({ port: 0 }, (err) => {
|
|
454
454
|
t.error(err)
|
|
455
455
|
fastify.server.unref()
|
|
456
456
|
|
package/test/bodyLimit.test.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const pem = require('pem')
|
|
5
|
-
|
|
6
|
-
const createCertificate = util.promisify(pem.createCertificate)
|
|
3
|
+
const selfCert = require('self-cert')
|
|
7
4
|
|
|
8
5
|
async function buildCertificate () {
|
|
9
6
|
// "global" is used in here because "t.context" is only supported by "t.beforeEach" and "t.afterEach"
|
|
10
7
|
// For the test case which execute this code which will be using `t.before` and it can reduce the
|
|
11
8
|
// number of times executing it.
|
|
12
9
|
if (!global.context || !global.context.cert || !global.context.key) {
|
|
13
|
-
const
|
|
10
|
+
const certs = selfCert({
|
|
11
|
+
expires: new Date(Date.now() + 86400000)
|
|
12
|
+
})
|
|
14
13
|
global.context = {
|
|
15
|
-
cert:
|
|
16
|
-
key:
|
|
14
|
+
cert: certs.certificate,
|
|
15
|
+
key: certs.privateKey
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
18
|
}
|
|
@@ -17,7 +17,7 @@ test('case insensitive', t => {
|
|
|
17
17
|
reply.send({ hello: 'world' })
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
fastify.listen(0, err => {
|
|
20
|
+
fastify.listen({ port: 0 }, err => {
|
|
21
21
|
t.error(err)
|
|
22
22
|
|
|
23
23
|
sget({
|
|
@@ -45,7 +45,7 @@ test('case insensitive inject', t => {
|
|
|
45
45
|
reply.send({ hello: 'world' })
|
|
46
46
|
})
|
|
47
47
|
|
|
48
|
-
fastify.listen(0, err => {
|
|
48
|
+
fastify.listen({ port: 0 }, err => {
|
|
49
49
|
t.error(err)
|
|
50
50
|
|
|
51
51
|
fastify.inject({
|
|
@@ -74,7 +74,7 @@ test('case insensitive (parametric)', t => {
|
|
|
74
74
|
reply.send({ hello: 'world' })
|
|
75
75
|
})
|
|
76
76
|
|
|
77
|
-
fastify.listen(0, err => {
|
|
77
|
+
fastify.listen({ port: 0 }, err => {
|
|
78
78
|
t.error(err)
|
|
79
79
|
|
|
80
80
|
sget({
|
|
@@ -103,7 +103,7 @@ test('case insensitive (wildcard)', t => {
|
|
|
103
103
|
reply.send({ hello: 'world' })
|
|
104
104
|
})
|
|
105
105
|
|
|
106
|
-
fastify.listen(0, err => {
|
|
106
|
+
fastify.listen({ port: 0 }, err => {
|
|
107
107
|
t.error(err)
|
|
108
108
|
|
|
109
109
|
sget({
|
|
@@ -15,7 +15,7 @@ test('Should return 503 while closing - pipelining', t => {
|
|
|
15
15
|
reply.send({ hello: 'world' })
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
fastify.listen(0, async err => {
|
|
18
|
+
fastify.listen({ port: 0 }, async err => {
|
|
19
19
|
t.error(err)
|
|
20
20
|
|
|
21
21
|
const instance = new Client('http://localhost:' + fastify.server.address().port, {
|
|
@@ -48,7 +48,7 @@ test('Should not return 503 while closing - pipelining - return503OnClosing', t
|
|
|
48
48
|
reply.send({ hello: 'world' })
|
|
49
49
|
})
|
|
50
50
|
|
|
51
|
-
fastify.listen(0, err => {
|
|
51
|
+
fastify.listen({ port: 0 }, err => {
|
|
52
52
|
t.error(err)
|
|
53
53
|
|
|
54
54
|
const instance = new Client('http://localhost:' + fastify.server.address().port, {
|
package/test/close.test.js
CHANGED
|
@@ -15,7 +15,7 @@ test('close callback', t => {
|
|
|
15
15
|
done()
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
fastify.listen(0, err => {
|
|
18
|
+
fastify.listen({ port: 0 }, err => {
|
|
19
19
|
t.error(err)
|
|
20
20
|
|
|
21
21
|
fastify.close((err) => {
|
|
@@ -39,7 +39,7 @@ test('inside register', t => {
|
|
|
39
39
|
done()
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
-
fastify.listen(0, err => {
|
|
42
|
+
fastify.listen({ port: 0 }, err => {
|
|
43
43
|
t.error(err)
|
|
44
44
|
|
|
45
45
|
fastify.close((err) => {
|
|
@@ -68,7 +68,7 @@ test('close order', t => {
|
|
|
68
68
|
done()
|
|
69
69
|
})
|
|
70
70
|
|
|
71
|
-
fastify.listen(0, err => {
|
|
71
|
+
fastify.listen({ port: 0 }, err => {
|
|
72
72
|
t.error(err)
|
|
73
73
|
|
|
74
74
|
fastify.close((err) => {
|
|
@@ -95,7 +95,7 @@ test('close order - async', async t => {
|
|
|
95
95
|
t.equal(order.shift(), 2)
|
|
96
96
|
})
|
|
97
97
|
|
|
98
|
-
await fastify.listen(0)
|
|
98
|
+
await fastify.listen({ port: 0 })
|
|
99
99
|
await fastify.close()
|
|
100
100
|
|
|
101
101
|
t.equal(order.shift(), 3)
|
|
@@ -211,7 +211,7 @@ t.test('Current opened connection should continue to work after closing and retu
|
|
|
211
211
|
reply.send({ hello: 'world' })
|
|
212
212
|
})
|
|
213
213
|
|
|
214
|
-
fastify.listen(0, err => {
|
|
214
|
+
fastify.listen({ port: 0 }, err => {
|
|
215
215
|
t.error(err)
|
|
216
216
|
|
|
217
217
|
const port = fastify.server.address().port
|
|
@@ -248,7 +248,7 @@ t.test('Current opened connection should not accept new incoming connections', t
|
|
|
248
248
|
}, 250)
|
|
249
249
|
})
|
|
250
250
|
|
|
251
|
-
fastify.listen(0, err => {
|
|
251
|
+
fastify.listen({ port: 0 }, err => {
|
|
252
252
|
t.error(err)
|
|
253
253
|
const instance = new Client('http://localhost:' + fastify.server.address().port)
|
|
254
254
|
instance.request({ path: '/', method: 'GET' }).then(data => {
|
|
@@ -264,11 +264,11 @@ test('Cannot be reopened the closed server without listen callback', async t =>
|
|
|
264
264
|
t.plan(2)
|
|
265
265
|
const fastify = Fastify()
|
|
266
266
|
|
|
267
|
-
await fastify.listen(0)
|
|
267
|
+
await fastify.listen({ port: 0 })
|
|
268
268
|
await fastify.close()
|
|
269
269
|
|
|
270
270
|
try {
|
|
271
|
-
await fastify.listen(0)
|
|
271
|
+
await fastify.listen({ port: 0 })
|
|
272
272
|
} catch (err) {
|
|
273
273
|
t.ok(err)
|
|
274
274
|
t.equal(err.code, 'FST_ERR_REOPENED_CLOSE_SERVER')
|
|
@@ -279,11 +279,11 @@ test('Cannot be reopened the closed server has listen callback', async t => {
|
|
|
279
279
|
t.plan(2)
|
|
280
280
|
const fastify = Fastify()
|
|
281
281
|
|
|
282
|
-
await fastify.listen(0)
|
|
282
|
+
await fastify.listen({ port: 0 })
|
|
283
283
|
await fastify.close()
|
|
284
284
|
|
|
285
285
|
await new Promise((resolve, reject) => {
|
|
286
|
-
fastify.listen(0, err => {
|
|
286
|
+
fastify.listen({ port: 0 }, err => {
|
|
287
287
|
reject(err)
|
|
288
288
|
})
|
|
289
289
|
}).catch(err => {
|
|
@@ -305,7 +305,7 @@ test('shutsdown while keep-alive connections are active (non-async)', t => {
|
|
|
305
305
|
reply.send({ hello: 'world' })
|
|
306
306
|
})
|
|
307
307
|
|
|
308
|
-
fastify.listen(0, (err, address) => {
|
|
308
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
309
309
|
t.error(err)
|
|
310
310
|
|
|
311
311
|
const client = new Client(
|