fastify 5.3.3 → 5.4.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 +2 -0
- package/build/build-validation.js +2 -1
- package/docs/Guides/Delay-Accepting-Requests.md +3 -3
- package/docs/Guides/Ecosystem.md +9 -5
- package/docs/Reference/ContentTypeParser.md +1 -1
- package/docs/Reference/Errors.md +2 -2
- package/docs/Reference/Hooks.md +14 -14
- package/docs/Reference/Logging.md +3 -3
- package/docs/Reference/Middleware.md +1 -1
- package/docs/Reference/Reply.md +8 -8
- package/docs/Reference/Request.md +1 -1
- package/docs/Reference/Routes.md +3 -3
- package/docs/Reference/Server.md +35 -21
- package/docs/Reference/Validation-and-Serialization.md +1 -1
- package/fastify.d.ts +2 -1
- package/fastify.js +14 -2
- package/lib/configValidator.js +1 -1
- package/lib/errors.js +6 -0
- package/lib/pluginOverride.js +3 -1
- package/lib/reply.js +7 -11
- package/lib/request.js +3 -10
- package/lib/symbols.js +1 -0
- package/lib/warnings.js +8 -0
- package/package.json +8 -4
- package/test/404s.test.js +226 -325
- package/test/allow-unsafe-regex.test.js +19 -48
- package/test/als.test.js +28 -40
- package/test/async-await.test.js +11 -2
- package/test/body-limit.test.js +41 -65
- package/test/build-certificate.js +1 -1
- package/test/custom-parser-async.test.js +17 -22
- package/test/decorator-namespace.test._js_ +3 -4
- package/test/diagnostics-channel/async-delay-request.test.js +7 -16
- package/test/diagnostics-channel/sync-delay-request.test.js +7 -16
- package/test/helper.js +1 -1
- package/test/hooks-async.test.js +248 -218
- package/test/hooks.test.js +910 -769
- package/test/http-methods/lock.test.js +31 -31
- package/test/http-methods/mkcol.test.js +5 -9
- package/test/http-methods/proppatch.test.js +23 -29
- package/test/http-methods/report.test.js +44 -69
- package/test/http-methods/search.test.js +67 -82
- package/test/http2/closing.test.js +38 -20
- package/test/http2/secure-with-fallback.test.js +28 -27
- package/test/https/https.test.js +56 -53
- package/test/internals/errors.test.js +1 -1
- package/test/internals/handle-request.test.js +49 -66
- package/test/issue-4959.test.js +12 -3
- package/test/listen.4.test.js +31 -43
- package/test/nullable-validation.test.js +33 -46
- package/test/output-validation.test.js +24 -26
- package/test/plugin.2.test.js +104 -86
- package/test/plugin.3.test.js +56 -35
- package/test/plugin.4.test.js +124 -119
- package/test/proto-poisoning.test.js +78 -97
- package/test/request-error.test.js +0 -46
- package/test/route-hooks.test.js +112 -92
- package/test/route-prefix.test.js +194 -133
- package/test/schema-serialization.test.js +177 -154
- package/test/schema-special-usage.test.js +165 -132
- package/test/schema-validation.test.js +242 -205
- package/test/set-error-handler.test.js +58 -1
- package/test/skip-reply-send.test.js +64 -69
- package/test/trust-proxy.test.js +32 -58
- package/test/types/fastify.test-d.ts +3 -0
- package/test/types/request.test-d.ts +1 -0
- package/test/url-rewriting.test.js +45 -62
- package/types/request.d.ts +1 -0
- package/.taprc +0 -7
- package/.vscode/settings.json +0 -22
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
4
|
const Fastify = require('..')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
5
|
|
|
7
|
-
test('Should rewrite url',
|
|
8
|
-
t.plan(
|
|
6
|
+
test('Should rewrite url', async t => {
|
|
7
|
+
t.plan(4)
|
|
9
8
|
const fastify = Fastify({
|
|
10
9
|
rewriteUrl (req) {
|
|
11
10
|
t.assert.strictEqual(req.url, '/this-would-404-without-url-rewrite')
|
|
@@ -22,24 +21,19 @@ test('Should rewrite url', (t, done) => {
|
|
|
22
21
|
}
|
|
23
22
|
})
|
|
24
23
|
|
|
25
|
-
fastify.listen({ port: 0 }
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
35
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
36
|
-
done()
|
|
37
|
-
})
|
|
38
|
-
})
|
|
24
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
25
|
+
|
|
26
|
+
t.after(() => fastify.close())
|
|
27
|
+
|
|
28
|
+
const result = await fetch(`${fastifyServer}/this-would-404-without-url-rewrite`)
|
|
29
|
+
|
|
30
|
+
t.assert.ok(result.ok)
|
|
31
|
+
t.assert.strictEqual(result.status, 200)
|
|
32
|
+
t.assert.deepStrictEqual(await result.json(), { hello: 'world' })
|
|
39
33
|
})
|
|
40
34
|
|
|
41
|
-
test('Should not rewrite if the url is the same',
|
|
42
|
-
t.plan(
|
|
35
|
+
test('Should not rewrite if the url is the same', async t => {
|
|
36
|
+
t.plan(3)
|
|
43
37
|
const fastify = Fastify({
|
|
44
38
|
rewriteUrl (req) {
|
|
45
39
|
t.assert.strictEqual(req.url, '/this-would-404-without-url-rewrite')
|
|
@@ -56,22 +50,18 @@ test('Should not rewrite if the url is the same', (t, done) => {
|
|
|
56
50
|
}
|
|
57
51
|
})
|
|
58
52
|
|
|
59
|
-
fastify.listen({ port: 0 }
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
t.assert.strictEqual(response.statusCode, 404)
|
|
68
|
-
done()
|
|
69
|
-
})
|
|
70
|
-
})
|
|
53
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
54
|
+
|
|
55
|
+
t.after(() => fastify.close())
|
|
56
|
+
|
|
57
|
+
const result = await fetch(`${fastifyServer}/this-would-404-without-url-rewrite`)
|
|
58
|
+
|
|
59
|
+
t.assert.ok(!result.ok)
|
|
60
|
+
t.assert.strictEqual(result.status, 404)
|
|
71
61
|
})
|
|
72
62
|
|
|
73
|
-
test('Should throw an error',
|
|
74
|
-
t.plan(
|
|
63
|
+
test('Should throw an error', async t => {
|
|
64
|
+
t.plan(2)
|
|
75
65
|
const fastify = Fastify({
|
|
76
66
|
rewriteUrl (req) {
|
|
77
67
|
t.assert.strictEqual(req.url, '/this-would-404-without-url-rewrite')
|
|
@@ -88,23 +78,20 @@ test('Should throw an error', (t, done) => {
|
|
|
88
78
|
}
|
|
89
79
|
})
|
|
90
80
|
|
|
91
|
-
fastify.listen({ port: 0 }
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
done()
|
|
102
|
-
})
|
|
103
|
-
})
|
|
81
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
82
|
+
|
|
83
|
+
t.after(() => fastify.close())
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
await fetch(`${fastifyServer}/this-would-404-without-url-rewrite`)
|
|
87
|
+
t.assert.fail('Expected fetch to throw an error')
|
|
88
|
+
} catch (err) {
|
|
89
|
+
t.assert.ok(err instanceof Error)
|
|
90
|
+
}
|
|
104
91
|
})
|
|
105
92
|
|
|
106
|
-
test('Should rewrite url but keep originalUrl unchanged',
|
|
107
|
-
t.plan(
|
|
93
|
+
test('Should rewrite url but keep originalUrl unchanged', async t => {
|
|
94
|
+
t.plan(6)
|
|
108
95
|
const fastify = Fastify({
|
|
109
96
|
rewriteUrl (req) {
|
|
110
97
|
t.assert.strictEqual(req.url, '/this-would-404-without-url-rewrite')
|
|
@@ -122,18 +109,14 @@ test('Should rewrite url but keep originalUrl unchanged', (t, done) => {
|
|
|
122
109
|
}
|
|
123
110
|
})
|
|
124
111
|
|
|
125
|
-
fastify.listen({ port: 0 }
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
136
|
-
done()
|
|
137
|
-
})
|
|
138
|
-
})
|
|
112
|
+
await fastify.listen({ port: 0 })
|
|
113
|
+
const port = fastify.server.address().port
|
|
114
|
+
|
|
115
|
+
t.after(() => fastify.close())
|
|
116
|
+
|
|
117
|
+
const result = await fetch(`http://localhost:${port}/this-would-404-without-url-rewrite`)
|
|
118
|
+
|
|
119
|
+
t.assert.ok(result.ok)
|
|
120
|
+
t.assert.strictEqual(result.status, 200)
|
|
121
|
+
t.assert.deepStrictEqual(await result.json(), { hello: 'world', hostname: 'localhost', port })
|
|
139
122
|
})
|
package/types/request.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface RequestRouteOptions<ContextConfig = ContextConfigDefault, Schem
|
|
|
32
32
|
config: FastifyContextConfig & FastifyRouteConfig & ContextConfig;
|
|
33
33
|
schema?: SchemaCompiler; // it is empty for 404 requests
|
|
34
34
|
handler: RouteHandlerMethod;
|
|
35
|
+
version?: string;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
/**
|
package/.taprc
DELETED
package/.vscode/settings.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"workbench.colorCustomizations": {
|
|
3
|
-
"[GitHub Dark]": {
|
|
4
|
-
"tab.activeBackground": "#0d0d0d",
|
|
5
|
-
"tab.activeBorder": "#ffff00"
|
|
6
|
-
},
|
|
7
|
-
"activityBar.background": "#7AC6C8",
|
|
8
|
-
"activityBar.foreground": "#0B2A34",
|
|
9
|
-
"activityBar.inactiveForeground": "#1e2021",
|
|
10
|
-
"activityBar.activeBorder": "#853937",
|
|
11
|
-
"activityBar.activeBackground": "#3F7F81",
|
|
12
|
-
"activityBar.border": "#3F7F81",
|
|
13
|
-
"titleBar.activeBackground": "#549B9D",
|
|
14
|
-
"titleBar.activeForeground": "#0B2A34",
|
|
15
|
-
"titleBar.inactiveBackground": "#727f7f",
|
|
16
|
-
"titleBar.inactiveForeground": "#1e2021",
|
|
17
|
-
"titleBar.border": "#3F7F81",
|
|
18
|
-
"statusBar.background": "#71ACAD",
|
|
19
|
-
"statusBar.foreground": "#0B2A34",
|
|
20
|
-
"statusBar.border": "#3F7F81"
|
|
21
|
-
}
|
|
22
|
-
}
|