fastify 5.1.0 → 5.2.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 +12 -7
- package/docs/Guides/Database.md +15 -15
- package/docs/Guides/Detecting-When-Clients-Abort.md +28 -28
- package/docs/Guides/Ecosystem.md +13 -7
- package/docs/Guides/Index.md +1 -1
- package/docs/Guides/Migration-Guide-V4.md +11 -11
- package/docs/Guides/Migration-Guide-V5.md +5 -5
- package/docs/Guides/Plugins-Guide.md +1 -1
- package/docs/Guides/Prototype-Poisoning.md +3 -3
- package/docs/Guides/Recommendations.md +9 -9
- package/docs/Guides/Serverless.md +5 -5
- package/docs/Guides/Testing.md +8 -8
- package/docs/Guides/Write-Plugin.md +1 -1
- package/docs/Guides/Write-Type-Provider.md +3 -3
- package/docs/Reference/Decorators.md +2 -2
- package/docs/Reference/Errors.md +2 -2
- package/docs/Reference/Hooks.md +7 -7
- package/docs/Reference/LTS.md +8 -0
- package/docs/Reference/Logging.md +5 -4
- package/docs/Reference/Reply.md +54 -53
- package/docs/Reference/Request.md +49 -43
- package/docs/Reference/Routes.md +7 -7
- package/docs/Reference/Server.md +31 -27
- package/docs/Reference/TypeScript.md +9 -9
- package/docs/Reference/Validation-and-Serialization.md +5 -5
- package/examples/typescript-server.ts +1 -1
- package/fastify.d.ts +4 -4
- package/fastify.js +1 -1
- package/lib/error-handler.js +9 -9
- package/lib/errors.js +1 -1
- package/lib/hooks.js +4 -1
- package/lib/request.js +11 -10
- package/package.json +3 -4
- package/test/{allowUnsafeRegex.test.js → allow-unsafe-regex.test.js} +4 -4
- package/test/async-dispose.test.js +0 -1
- package/test/async_hooks.test.js +4 -4
- package/test/buffer.test.js +4 -4
- package/test/build-certificate.js +1 -1
- package/test/bundler/README.md +5 -5
- package/test/case-insensitive.test.js +10 -10
- package/test/check.test.js +2 -3
- package/test/{childLoggerFactory.test.js → child-logger-factory.test.js} +1 -1
- package/test/client-timeout.test.js +1 -1
- package/test/close-pipelining.test.js +0 -1
- package/test/conditional-pino.test.js +3 -3
- package/test/content-length.test.js +53 -68
- package/test/content-parser.test.js +178 -167
- package/test/content-type.test.js +8 -9
- package/test/context-config.test.js +44 -54
- package/test/custom-parser.5.test.js +32 -32
- package/test/encapsulated-child-logger-factory.test.js +8 -8
- package/test/encapsulated-error-handler.test.js +20 -20
- package/test/fastify-instance.test.js +33 -34
- package/test/{findRoute.test.js → find-route.test.js} +11 -10
- package/test/fluent-schema.test.js +33 -36
- package/test/handler-context.test.js +11 -11
- package/test/has-route.test.js +12 -15
- package/test/header-overflow.test.js +13 -12
- package/test/hooks.on-ready.test.js +2 -2
- package/test/hooks.test.js +19 -19
- package/test/http-methods/head.test.js +0 -3
- package/test/imports.test.js +2 -2
- package/test/internals/errors.test.js +1 -1
- package/test/listen.5.test.js +9 -9
- package/test/{maxRequestsPerSocket.test.js → max-requests-per-socket.test.js} +30 -30
- package/test/middleware.test.js +4 -5
- package/test/noop-set.test.js +1 -1
- package/test/post-empty-body.test.js +18 -11
- package/test/pretty-print.test.js +59 -49
- package/test/proto-poisoning.test.js +42 -37
- package/test/reply-code.test.js +34 -32
- package/test/{reply-earlyHints.test.js → reply-early-hints.test.js} +21 -19
- package/test/request-header-host.test.js +154 -12
- package/test/request-id.test.js +31 -25
- package/test/{requestTimeout.test.js → request-timeout.test.js} +11 -11
- package/test/route.3.test.js +3 -2
- package/test/route.8.test.js +20 -20
- package/test/router-options.test.js +80 -77
- package/test/schema-examples.test.js +72 -38
- package/test/server.test.js +12 -12
- package/test/set-error-handler.test.js +2 -3
- package/test/stream-serializers.test.js +10 -7
- package/test/sync-routes.test.js +18 -18
- package/test/trust-proxy.test.js +51 -45
- package/test/type-provider.test.js +8 -6
- package/test/types/content-type-parser.test-d.ts +1 -1
- package/test/types/fastify.test-d.ts +4 -4
- package/test/types/instance.test-d.ts +3 -1
- package/test/types/logger.test-d.ts +2 -2
- package/test/types/plugin.test-d.ts +2 -2
- package/test/types/register.test-d.ts +2 -2
- package/test/types/reply.test-d.ts +1 -1
- package/test/types/route.test-d.ts +1 -1
- package/test/types/serverFactory.test-d.ts +1 -1
- package/test/types/type-provider.test-d.ts +1 -1
- package/test/url-rewriting.test.js +35 -38
- package/test/{useSemicolonDelimiter.test.js → use-semicolon-delimiter.test.js} +30 -30
- package/test/validation-error-handling.test.js +259 -285
- package/types/hooks.d.ts +1 -1
- package/types/instance.d.ts +9 -2
- package/types/reply.d.ts +1 -1
- package/types/request.d.ts +0 -4
- package/types/serverFactory.d.ts +3 -3
- package/types/utils.d.ts +3 -3
- /package/test/{connectionTimeout.test.js → connection-timeout.test.js} +0 -0
- /package/test/internals/{contentTypeParser.test.js → content-type-parser.test.js} +0 -0
- /package/test/internals/{handleRequest.test.js → handle-request.test.js} +0 -0
- /package/test/internals/{hookRunner.test.js → hook-runner.test.js} +0 -0
- /package/test/internals/{initialConfig.test.js → initial-config.test.js} +0 -0
- /package/test/internals/{reqIdGenFactory.test.js → req-id-gen-factory.test.js} +0 -0
- /package/test/{wrapThenable.test.js → wrap-thenable.test.js} +0 -0
package/test/server.test.js
CHANGED
|
@@ -85,7 +85,7 @@ test('abort signal', async t => {
|
|
|
85
85
|
await t.test('listen should not start server', (t, end) => {
|
|
86
86
|
t.plan(2)
|
|
87
87
|
function onClose (instance, done) {
|
|
88
|
-
t.assert.
|
|
88
|
+
t.assert.strictEqual(instance, fastify)
|
|
89
89
|
done()
|
|
90
90
|
end()
|
|
91
91
|
}
|
|
@@ -103,7 +103,7 @@ test('abort signal', async t => {
|
|
|
103
103
|
await t.test('listen should not start server if already aborted', (t, end) => {
|
|
104
104
|
t.plan(2)
|
|
105
105
|
function onClose (instance, done) {
|
|
106
|
-
t.assert.
|
|
106
|
+
t.assert.strictEqual(instance, fastify)
|
|
107
107
|
done()
|
|
108
108
|
end()
|
|
109
109
|
}
|
|
@@ -134,21 +134,19 @@ test('abort signal', async t => {
|
|
|
134
134
|
})
|
|
135
135
|
})
|
|
136
136
|
|
|
137
|
-
test('#5180 - preClose should be called before closing secondary server', (t
|
|
137
|
+
test('#5180 - preClose should be called before closing secondary server', async (t) => {
|
|
138
138
|
t.plan(2)
|
|
139
139
|
const fastify = Fastify({ forceCloseConnections: true })
|
|
140
140
|
let flag = false
|
|
141
141
|
t.after(() => fastify.close())
|
|
142
142
|
|
|
143
|
-
fastify.addHook('preClose',
|
|
143
|
+
fastify.addHook('preClose', () => {
|
|
144
144
|
flag = true
|
|
145
145
|
})
|
|
146
146
|
|
|
147
147
|
fastify.get('/', async (req, reply) => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
})
|
|
151
|
-
|
|
148
|
+
// request will be pending for 1 second to simulate a slow request
|
|
149
|
+
await new Promise((resolve) => { setTimeout(resolve, 1000) })
|
|
152
150
|
return { hello: 'world' }
|
|
153
151
|
})
|
|
154
152
|
|
|
@@ -177,12 +175,14 @@ test('#5180 - preClose should be called before closing secondary server', (t, en
|
|
|
177
175
|
() => { t.assert.fail('Request should not succeed') },
|
|
178
176
|
() => {
|
|
179
177
|
t.assert.ok(flag)
|
|
180
|
-
end()
|
|
181
178
|
}
|
|
182
179
|
)
|
|
183
180
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}, 250)
|
|
181
|
+
// Close the server while the slow request is pending
|
|
182
|
+
setTimeout(fastify.close, 250)
|
|
187
183
|
})
|
|
184
|
+
|
|
185
|
+
// Wait 1000ms to ensure that the test is finished and async operations are
|
|
186
|
+
// completed
|
|
187
|
+
await new Promise((resolve) => { setTimeout(resolve, 1000) })
|
|
188
188
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const Fastify = require('..')
|
|
6
5
|
const { FST_ERR_ERROR_HANDLER_NOT_FN } = require('../lib/errors')
|
|
7
6
|
|
|
@@ -9,5 +8,5 @@ test('setErrorHandler should throw an error if the handler is not a function', t
|
|
|
9
8
|
t.plan(1)
|
|
10
9
|
const fastify = Fastify()
|
|
11
10
|
|
|
12
|
-
t.throws(() => fastify.setErrorHandler('not a function'), new FST_ERR_ERROR_HANDLER_NOT_FN())
|
|
11
|
+
t.assert.throws(() => fastify.setErrorHandler('not a function'), new FST_ERR_ERROR_HANDLER_NOT_FN())
|
|
13
12
|
})
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const Fastify = require('..')
|
|
6
5
|
const Reply = require('../lib/reply')
|
|
7
6
|
|
|
8
|
-
test('should serialize reply when response stream is ended', t => {
|
|
9
|
-
t.plan(
|
|
7
|
+
test('should serialize reply when response stream is ended', (t, done) => {
|
|
8
|
+
t.plan(5)
|
|
9
|
+
|
|
10
10
|
const stream = require('node:stream')
|
|
11
11
|
const fastify = Fastify({
|
|
12
12
|
logger: {
|
|
13
13
|
serializers: {
|
|
14
14
|
res (reply) {
|
|
15
|
-
t.
|
|
15
|
+
t.assert.strictEqual(reply instanceof Reply, true)
|
|
16
|
+
t.assert.ok('passed')
|
|
16
17
|
return reply
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -27,11 +28,13 @@ test('should serialize reply when response stream is ended', t => {
|
|
|
27
28
|
reply.raw.end(Buffer.from('hello\n'))
|
|
28
29
|
})
|
|
29
30
|
|
|
31
|
+
t.after(() => fastify.close())
|
|
32
|
+
|
|
30
33
|
fastify.inject({
|
|
31
34
|
url: '/error',
|
|
32
35
|
method: 'GET'
|
|
33
36
|
}, (err) => {
|
|
34
|
-
t.
|
|
35
|
-
|
|
37
|
+
t.assert.ifError(err)
|
|
38
|
+
done()
|
|
36
39
|
})
|
|
37
40
|
})
|
package/test/sync-routes.test.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { test } = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const Fastify = require('..')
|
|
5
5
|
|
|
6
6
|
test('sync route', async t => {
|
|
7
|
-
const
|
|
8
|
-
t.
|
|
9
|
-
|
|
10
|
-
const res = await
|
|
11
|
-
t.
|
|
12
|
-
t.
|
|
7
|
+
const fastify = Fastify()
|
|
8
|
+
t.after(() => fastify.close())
|
|
9
|
+
fastify.get('/', () => 'hello world')
|
|
10
|
+
const res = await fastify.inject('/')
|
|
11
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
12
|
+
t.assert.strictEqual(res.body, 'hello world')
|
|
13
13
|
})
|
|
14
14
|
|
|
15
15
|
test('sync route return null', async t => {
|
|
16
|
-
const
|
|
17
|
-
t.
|
|
18
|
-
|
|
19
|
-
const res = await
|
|
20
|
-
t.
|
|
21
|
-
t.
|
|
16
|
+
const fastify = Fastify()
|
|
17
|
+
t.after(() => fastify.close())
|
|
18
|
+
fastify.get('/', () => null)
|
|
19
|
+
const res = await fastify.inject('/')
|
|
20
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
21
|
+
t.assert.strictEqual(res.body, 'null')
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
test('sync route, error', async t => {
|
|
25
|
-
const
|
|
26
|
-
t.
|
|
27
|
-
|
|
25
|
+
const fastify = Fastify()
|
|
26
|
+
t.after(() => fastify.close())
|
|
27
|
+
fastify.get('/', () => {
|
|
28
28
|
throw new Error('kaboom')
|
|
29
29
|
})
|
|
30
|
-
const res = await
|
|
31
|
-
t.
|
|
30
|
+
const res = await fastify.inject('/')
|
|
31
|
+
t.assert.strictEqual(res.statusCode, 500)
|
|
32
32
|
})
|
package/test/trust-proxy.test.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const { test, before } = t
|
|
3
|
+
const { test, before } = require('node:test')
|
|
5
4
|
const sget = require('simple-get').concat
|
|
6
5
|
const fastify = require('..')
|
|
7
6
|
const helper = require('./helper')
|
|
8
7
|
|
|
9
|
-
const
|
|
8
|
+
const noop = () => {}
|
|
9
|
+
|
|
10
|
+
const sgetForwardedRequest = (app, forHeader, path, protoHeader, testCaseDone) => {
|
|
10
11
|
const headers = {
|
|
11
12
|
'X-Forwarded-For': forHeader,
|
|
12
13
|
'X-Forwarded-Host': 'example.com'
|
|
@@ -18,30 +19,30 @@ const sgetForwardedRequest = (app, forHeader, path, protoHeader) => {
|
|
|
18
19
|
method: 'GET',
|
|
19
20
|
headers,
|
|
20
21
|
url: 'http://localhost:' + app.server.address().port + path
|
|
21
|
-
},
|
|
22
|
+
}, testCaseDone || noop)
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
const testRequestValues = (t, req, options) => {
|
|
25
26
|
if (options.ip) {
|
|
26
|
-
t.ok(req.ip, 'ip is defined')
|
|
27
|
-
t.
|
|
27
|
+
t.assert.ok(req.ip, 'ip is defined')
|
|
28
|
+
t.assert.strictEqual(req.ip, options.ip, 'gets ip from x-forwarded-for')
|
|
28
29
|
}
|
|
29
30
|
if (options.host) {
|
|
30
|
-
t.ok(req.host, 'host is defined')
|
|
31
|
-
t.
|
|
32
|
-
t.ok(req.hostname)
|
|
33
|
-
t.
|
|
31
|
+
t.assert.ok(req.host, 'host is defined')
|
|
32
|
+
t.assert.strictEqual(req.host, options.host, 'gets host from x-forwarded-host')
|
|
33
|
+
t.assert.ok(req.hostname)
|
|
34
|
+
t.assert.strictEqual(req.hostname, options.host, 'gets hostname from x-forwarded-host')
|
|
34
35
|
}
|
|
35
36
|
if (options.ips) {
|
|
36
|
-
t.
|
|
37
|
+
t.assert.deepStrictEqual(req.ips, options.ips, 'gets ips from x-forwarded-for')
|
|
37
38
|
}
|
|
38
39
|
if (options.protocol) {
|
|
39
|
-
t.ok(req.protocol, 'protocol is defined')
|
|
40
|
-
t.
|
|
40
|
+
t.assert.ok(req.protocol, 'protocol is defined')
|
|
41
|
+
t.assert.strictEqual(req.protocol, options.protocol, 'gets protocol from x-forwarded-proto')
|
|
41
42
|
}
|
|
42
43
|
if (options.port) {
|
|
43
|
-
t.ok(req.port, 'port is defined')
|
|
44
|
-
t.
|
|
44
|
+
t.assert.ok(req.port, 'port is defined')
|
|
45
|
+
t.assert.strictEqual(req.port, options.port, 'port is taken from x-forwarded-for or host')
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -50,11 +51,13 @@ before(async function () {
|
|
|
50
51
|
[localhost] = await helper.getLoopbackHost()
|
|
51
52
|
})
|
|
52
53
|
|
|
53
|
-
test('trust proxy, not add properties to node req', (t) => {
|
|
54
|
+
test('trust proxy, not add properties to node req', (t, done) => {
|
|
54
55
|
t.plan(14)
|
|
55
56
|
const app = fastify({
|
|
56
57
|
trustProxy: true
|
|
57
58
|
})
|
|
59
|
+
t.after(() => app.close())
|
|
60
|
+
|
|
58
61
|
app.get('/trustproxy', function (req, reply) {
|
|
59
62
|
testRequestValues(t, req, { ip: '1.1.1.1', host: 'example.com', port: app.server.address().port })
|
|
60
63
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
@@ -65,17 +68,23 @@ test('trust proxy, not add properties to node req', (t) => {
|
|
|
65
68
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
66
69
|
})
|
|
67
70
|
|
|
68
|
-
t.teardown(app.close.bind(app))
|
|
69
|
-
|
|
70
71
|
app.listen({ port: 0 }, (err) => {
|
|
71
72
|
app.server.unref()
|
|
72
|
-
t.
|
|
73
|
-
|
|
74
|
-
sgetForwardedRequest(app, '
|
|
73
|
+
t.assert.ifError(err)
|
|
74
|
+
|
|
75
|
+
sgetForwardedRequest(app, '1.1.1.1', '/trustproxy', undefined, completed)
|
|
76
|
+
sgetForwardedRequest(app, '2.2.2.2, 1.1.1.1', '/trustproxychain', undefined, completed)
|
|
77
|
+
|
|
78
|
+
let pending = 2
|
|
79
|
+
function completed () {
|
|
80
|
+
if (--pending === 0) {
|
|
81
|
+
done()
|
|
82
|
+
}
|
|
83
|
+
}
|
|
75
84
|
})
|
|
76
85
|
})
|
|
77
86
|
|
|
78
|
-
test('trust proxy chain', (t) => {
|
|
87
|
+
test('trust proxy chain', (t, done) => {
|
|
79
88
|
t.plan(9)
|
|
80
89
|
const app = fastify({
|
|
81
90
|
trustProxy: [localhost, '192.168.1.1']
|
|
@@ -86,16 +95,15 @@ test('trust proxy chain', (t) => {
|
|
|
86
95
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
87
96
|
})
|
|
88
97
|
|
|
89
|
-
t.teardown(app.close.bind(app))
|
|
90
|
-
|
|
91
98
|
app.listen({ port: 0 }, (err) => {
|
|
92
99
|
app.server.unref()
|
|
93
|
-
t.
|
|
94
|
-
|
|
100
|
+
t.assert.ifError(err)
|
|
101
|
+
t.after(() => app.close())
|
|
102
|
+
sgetForwardedRequest(app, '192.168.1.1, 1.1.1.1', '/trustproxychain', undefined, done)
|
|
95
103
|
})
|
|
96
104
|
})
|
|
97
105
|
|
|
98
|
-
test('trust proxy function', (t) => {
|
|
106
|
+
test('trust proxy function', (t, done) => {
|
|
99
107
|
t.plan(9)
|
|
100
108
|
const app = fastify({
|
|
101
109
|
trustProxy: (address) => address === localhost
|
|
@@ -105,16 +113,15 @@ test('trust proxy function', (t) => {
|
|
|
105
113
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
106
114
|
})
|
|
107
115
|
|
|
108
|
-
t.teardown(app.close.bind(app))
|
|
109
|
-
|
|
110
116
|
app.listen({ port: 0 }, (err) => {
|
|
111
117
|
app.server.unref()
|
|
112
|
-
t.
|
|
113
|
-
|
|
118
|
+
t.assert.ifError(err)
|
|
119
|
+
t.after(() => app.close())
|
|
120
|
+
sgetForwardedRequest(app, '1.1.1.1', '/trustproxyfunc', undefined, done)
|
|
114
121
|
})
|
|
115
122
|
})
|
|
116
123
|
|
|
117
|
-
test('trust proxy number', (t) => {
|
|
124
|
+
test('trust proxy number', (t, done) => {
|
|
118
125
|
t.plan(10)
|
|
119
126
|
const app = fastify({
|
|
120
127
|
trustProxy: 1
|
|
@@ -124,16 +131,15 @@ test('trust proxy number', (t) => {
|
|
|
124
131
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
125
132
|
})
|
|
126
133
|
|
|
127
|
-
t.teardown(app.close.bind(app))
|
|
128
|
-
|
|
129
134
|
app.listen({ port: 0 }, (err) => {
|
|
130
135
|
app.server.unref()
|
|
131
|
-
t.
|
|
132
|
-
|
|
136
|
+
t.assert.ifError(err)
|
|
137
|
+
t.after(() => app.close())
|
|
138
|
+
sgetForwardedRequest(app, '2.2.2.2, 1.1.1.1', '/trustproxynumber', undefined, done)
|
|
133
139
|
})
|
|
134
140
|
})
|
|
135
141
|
|
|
136
|
-
test('trust proxy IP addresses', (t) => {
|
|
142
|
+
test('trust proxy IP addresses', (t, done) => {
|
|
137
143
|
t.plan(10)
|
|
138
144
|
const app = fastify({
|
|
139
145
|
trustProxy: `${localhost}, 2.2.2.2`
|
|
@@ -143,16 +149,15 @@ test('trust proxy IP addresses', (t) => {
|
|
|
143
149
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
144
150
|
})
|
|
145
151
|
|
|
146
|
-
t.teardown(app.close.bind(app))
|
|
147
|
-
|
|
148
152
|
app.listen({ port: 0 }, (err) => {
|
|
149
153
|
app.server.unref()
|
|
150
|
-
t.
|
|
151
|
-
|
|
154
|
+
t.assert.ifError(err)
|
|
155
|
+
t.after(() => app.close())
|
|
156
|
+
sgetForwardedRequest(app, '3.3.3.3, 2.2.2.2, 1.1.1.1', '/trustproxyipaddrs', undefined, done)
|
|
152
157
|
})
|
|
153
158
|
})
|
|
154
159
|
|
|
155
|
-
test('trust proxy protocol', (t) => {
|
|
160
|
+
test('trust proxy protocol', (t, done) => {
|
|
156
161
|
t.plan(31)
|
|
157
162
|
const app = fastify({
|
|
158
163
|
trustProxy: true
|
|
@@ -170,13 +175,14 @@ test('trust proxy protocol', (t) => {
|
|
|
170
175
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
171
176
|
})
|
|
172
177
|
|
|
173
|
-
t.
|
|
178
|
+
t.after(() => app.close())
|
|
174
179
|
|
|
175
180
|
app.listen({ port: 0 }, (err) => {
|
|
176
181
|
app.server.unref()
|
|
177
|
-
t.
|
|
182
|
+
t.assert.ifError(err)
|
|
178
183
|
sgetForwardedRequest(app, '1.1.1.1', '/trustproxyprotocol', 'lorem')
|
|
179
184
|
sgetForwardedRequest(app, '1.1.1.1', '/trustproxynoprotocol')
|
|
180
|
-
sgetForwardedRequest
|
|
185
|
+
// Allow for sgetForwardedRequest requests above to finish
|
|
186
|
+
setTimeout(() => sgetForwardedRequest(app, '1.1.1.1', '/trustproxyprotocols', 'ipsum, dolor', done))
|
|
181
187
|
})
|
|
182
188
|
})
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { test } = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const Fastify = require('..')
|
|
5
5
|
|
|
6
|
-
test('Should export withTypeProvider function', t => {
|
|
6
|
+
test('Should export withTypeProvider function', (t, done) => {
|
|
7
7
|
t.plan(1)
|
|
8
8
|
try {
|
|
9
9
|
Fastify().withTypeProvider()
|
|
10
|
-
t.pass
|
|
10
|
+
t.assert.ok('pass')
|
|
11
|
+
done()
|
|
11
12
|
} catch (e) {
|
|
12
|
-
t.fail()
|
|
13
|
+
t.assert.fail(e)
|
|
13
14
|
}
|
|
14
15
|
})
|
|
15
16
|
|
|
16
|
-
test('Should return same instance', t => {
|
|
17
|
+
test('Should return same instance', (t, done) => {
|
|
17
18
|
t.plan(1)
|
|
18
19
|
const fastify = Fastify()
|
|
19
|
-
t.
|
|
20
|
+
t.assert.strictEqual(fastify, fastify.withTypeProvider())
|
|
21
|
+
done()
|
|
20
22
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fastify, { FastifyBodyParser } from '../../fastify'
|
|
2
2
|
import { expectError, expectType } from 'tsd'
|
|
3
|
-
import { IncomingMessage } from 'http'
|
|
3
|
+
import { IncomingMessage } from 'node:http'
|
|
4
4
|
import { FastifyRequest } from '../../types/request'
|
|
5
5
|
|
|
6
6
|
expectType<void>(fastify().addContentTypeParser('contentType', function (request, payload, done) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ErrorObject as AjvErrorObject } from 'ajv'
|
|
2
|
-
import * as http from 'http'
|
|
3
|
-
import * as http2 from 'http2'
|
|
4
|
-
import * as https from 'https'
|
|
5
|
-
import { Socket } from 'net'
|
|
2
|
+
import * as http from 'node:http'
|
|
3
|
+
import * as http2 from 'node:http2'
|
|
4
|
+
import * as https from 'node:https'
|
|
5
|
+
import { Socket } from 'node:net'
|
|
6
6
|
import { expectAssignable, expectError, expectNotAssignable, expectType } from 'tsd'
|
|
7
7
|
import fastify, {
|
|
8
8
|
ConnectionError,
|
|
@@ -13,7 +13,7 @@ import { HookHandlerDoneFunction } from '../../types/hooks'
|
|
|
13
13
|
import { FastifyReply } from '../../types/reply'
|
|
14
14
|
import { FastifyRequest } from '../../types/request'
|
|
15
15
|
import { FastifySchemaControllerOptions, FastifySchemaCompiler, FastifySerializerCompiler } from '../../types/schema'
|
|
16
|
-
import { AddressInfo } from 'net'
|
|
16
|
+
import { AddressInfo } from 'node:net'
|
|
17
17
|
import { Bindings, ChildLoggerOptions } from '../../types/logger'
|
|
18
18
|
|
|
19
19
|
const server = fastify()
|
|
@@ -193,6 +193,8 @@ function invalidSchemaErrorFormatter (err: Error) {
|
|
|
193
193
|
}
|
|
194
194
|
expectError(server.setSchemaErrorFormatter(invalidSchemaErrorFormatter))
|
|
195
195
|
|
|
196
|
+
expectType<FastifyInstance>(server.addHttpMethod('SEARCH', { hasBody: true }))
|
|
197
|
+
|
|
196
198
|
// test listen opts objects
|
|
197
199
|
expectAssignable<PromiseLike<string>>(server.listen())
|
|
198
200
|
expectAssignable<PromiseLike<string>>(server.listen({ port: 3000 }))
|
|
@@ -7,8 +7,8 @@ import fastify, {
|
|
|
7
7
|
FastifyReply,
|
|
8
8
|
FastifyBaseLogger
|
|
9
9
|
} from '../../fastify'
|
|
10
|
-
import { Server, IncomingMessage, ServerResponse } from 'http'
|
|
11
|
-
import * as fs from 'fs'
|
|
10
|
+
import { Server, IncomingMessage, ServerResponse } from 'node:http'
|
|
11
|
+
import * as fs from 'node:fs'
|
|
12
12
|
import P from 'pino'
|
|
13
13
|
import { ResSerializerReply } from '../../types/logger'
|
|
14
14
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fastify, { FastifyInstance, FastifyPluginOptions, SafePromiseLike } from '../../fastify'
|
|
2
|
-
import * as http from 'http'
|
|
3
|
-
import * as https from 'https'
|
|
2
|
+
import * as http from 'node:http'
|
|
3
|
+
import * as https from 'node:https'
|
|
4
4
|
import { expectType, expectError, expectAssignable } from 'tsd'
|
|
5
5
|
import { FastifyPluginCallback, FastifyPluginAsync } from '../../types/plugin'
|
|
6
6
|
import { FastifyError } from '@fastify/error'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expectAssignable, expectError, expectType } from 'tsd'
|
|
2
|
-
import { IncomingMessage, Server, ServerResponse } from 'http'
|
|
3
|
-
import { Http2Server, Http2ServerRequest, Http2ServerResponse } from 'http2'
|
|
2
|
+
import { IncomingMessage, Server, ServerResponse } from 'node:http'
|
|
3
|
+
import { Http2Server, Http2ServerRequest, Http2ServerResponse } from 'node:http2'
|
|
4
4
|
import fastify, { FastifyInstance, FastifyError, FastifyLoggerInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions, RawServerDefault } from '../../fastify'
|
|
5
5
|
|
|
6
6
|
const testPluginCallback: FastifyPluginCallback = function (instance, opts, done) { }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Buffer } from 'buffer'
|
|
1
|
+
import { Buffer } from 'node:buffer'
|
|
2
2
|
import { expectAssignable, expectError, expectType } from 'tsd'
|
|
3
3
|
import fastify, { FastifyContextConfig, FastifyReply, FastifyRequest, FastifySchema, FastifyTypeProviderDefault, RawRequestDefaultExpression, RouteHandler, RouteHandlerMethod } from '../../fastify'
|
|
4
4
|
import { FastifyInstance } from '../../types/instance'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FastifyError } from '@fastify/error'
|
|
2
|
-
import * as http from 'http'
|
|
2
|
+
import * as http from 'node:http'
|
|
3
3
|
import { expectAssignable, expectError, expectType } from 'tsd'
|
|
4
4
|
import fastify, { FastifyInstance, FastifyReply, FastifyRequest, RouteHandlerMethod } from '../../fastify'
|
|
5
5
|
import { RequestPayload } from '../../types/hooks'
|
|
@@ -8,7 +8,7 @@ import fastify, {
|
|
|
8
8
|
SafePromiseLike
|
|
9
9
|
} from '../../fastify'
|
|
10
10
|
import { expectAssignable, expectError, expectType } from 'tsd'
|
|
11
|
-
import { IncomingHttpHeaders } from 'http'
|
|
11
|
+
import { IncomingHttpHeaders } from 'node:http'
|
|
12
12
|
import { Type, TSchema, Static } from '@sinclair/typebox'
|
|
13
13
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts'
|
|
14
14
|
|