@fastify/express 4.0.2 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +1 -1
- package/.github/workflows/ci.yml +12 -2
- package/LICENSE +4 -1
- package/README.md +3 -3
- package/index.js +5 -1
- package/package.json +5 -9
- package/test/404s.test.js +83 -114
- package/test/application.test.js +48 -80
- package/test/basic.test.js +157 -284
- package/test/enhance-request.test.js +76 -79
- package/test/form-data.test.js +57 -69
- package/test/hooks.test.js +15 -17
- package/test/middleware.test.js +228 -183
package/.github/dependabot.yml
CHANGED
package/.github/workflows/ci.yml
CHANGED
|
@@ -4,7 +4,6 @@ on:
|
|
|
4
4
|
push:
|
|
5
5
|
branches:
|
|
6
6
|
- main
|
|
7
|
-
- master
|
|
8
7
|
- next
|
|
9
8
|
- 'v*'
|
|
10
9
|
paths-ignore:
|
|
@@ -15,9 +14,20 @@ on:
|
|
|
15
14
|
- 'docs/**'
|
|
16
15
|
- '*.md'
|
|
17
16
|
|
|
17
|
+
# This allows a subsequently queued workflow run to interrupt previous runs
|
|
18
|
+
concurrency:
|
|
19
|
+
group: "${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
|
|
20
|
+
cancel-in-progress: true
|
|
21
|
+
|
|
22
|
+
permissions:
|
|
23
|
+
contents: read
|
|
24
|
+
|
|
18
25
|
jobs:
|
|
19
26
|
test:
|
|
27
|
+
permissions:
|
|
28
|
+
contents: write
|
|
29
|
+
pull-requests: write
|
|
20
30
|
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
|
|
21
31
|
with:
|
|
22
|
-
lint: true
|
|
23
32
|
license-check: true
|
|
33
|
+
lint: true
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2019 Fastify
|
|
3
|
+
Copyright (c) 2019-present The Fastify team
|
|
4
|
+
|
|
5
|
+
The Fastify team members are listed at https://github.com/fastify/fastify#team.
|
|
4
6
|
|
|
5
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
8
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -19,3 +21,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
21
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
22
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
23
|
SOFTWARE.
|
|
24
|
+
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @fastify/express
|
|
2
2
|
|
|
3
|
-
[](https://github.com/fastify/fastify-express/actions/workflows/ci.yml)
|
|
4
4
|
[](https://www.npmjs.com/package/@fastify/express)
|
|
5
5
|
[](https://github.com/neostandard/neostandard)
|
|
6
6
|
|
|
@@ -26,8 +26,8 @@ npm i @fastify/express
|
|
|
26
26
|
### Compatibility
|
|
27
27
|
| Plugin version | Fastify version |
|
|
28
28
|
| ---------------|-----------------|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
29
|
+
| `>=4.x` | `^5.x` |
|
|
30
|
+
| `>=2.x <4.x` | `^4.x` |
|
|
31
31
|
| `^1.x` | `^3.x` |
|
|
32
32
|
| `^0.x` | `^2.x` |
|
|
33
33
|
|
package/index.js
CHANGED
|
@@ -41,6 +41,9 @@ function fastifyExpress (fastify, options, next) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const { url } = req.raw
|
|
44
|
+
|
|
45
|
+
const decodedUrl = decodeURI(url)
|
|
46
|
+
req.raw.url = decodedUrl
|
|
44
47
|
req.raw.originalUrl = url
|
|
45
48
|
req.raw.id = req.id
|
|
46
49
|
req.raw.hostname = req.hostname
|
|
@@ -50,7 +53,7 @@ function fastifyExpress (fastify, options, next) {
|
|
|
50
53
|
reply.raw.log = req.log
|
|
51
54
|
reply.raw.send = function send (...args) {
|
|
52
55
|
// Restore req.raw.url to its original value https://github.com/fastify/fastify-express/issues/11
|
|
53
|
-
req.raw.url =
|
|
56
|
+
req.raw.url = decodedUrl
|
|
54
57
|
return reply.send.apply(reply, args)
|
|
55
58
|
}
|
|
56
59
|
|
|
@@ -59,6 +62,7 @@ function fastifyExpress (fastify, options, next) {
|
|
|
59
62
|
req.raw.body = req.body
|
|
60
63
|
}
|
|
61
64
|
// backward compatibility for cookie-parser
|
|
65
|
+
/* c8 ignore next 3 */
|
|
62
66
|
if (req.cookies) {
|
|
63
67
|
req.raw.cookies = req.cookies
|
|
64
68
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/express",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"description": "Express compatibility layer for Fastify",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"lint": "eslint",
|
|
10
10
|
"lint:fix": "eslint --fix",
|
|
11
11
|
"test": "npm run test:unit && npm run test:typescript",
|
|
12
|
-
"test:unit": "
|
|
12
|
+
"test:unit": "c8 --100 --reporter html node --test",
|
|
13
13
|
"test:typescript": "tsd"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"@types/express": "^5.0.0",
|
|
64
64
|
"@types/node": "*",
|
|
65
65
|
"body-parser": "^1.20.2",
|
|
66
|
+
"c8": "^10.1.3",
|
|
66
67
|
"cors": "^2.8.5",
|
|
67
68
|
"eslint": "^9.17.0",
|
|
68
69
|
"fastify": "^5.0.0",
|
|
@@ -70,10 +71,8 @@
|
|
|
70
71
|
"neostandard": "^0.12.0",
|
|
71
72
|
"passport": "^0.7.0",
|
|
72
73
|
"passport-http-bearer": "^1.0.1",
|
|
73
|
-
"serve-static": "^
|
|
74
|
-
"
|
|
75
|
-
"tap": "^21.0.0",
|
|
76
|
-
"tsd": "^0.31.0"
|
|
74
|
+
"serve-static": "^2.2.0",
|
|
75
|
+
"tsd": "^0.33.0"
|
|
77
76
|
},
|
|
78
77
|
"dependencies": {
|
|
79
78
|
"express": "^4.18.3",
|
|
@@ -84,8 +83,5 @@
|
|
|
84
83
|
},
|
|
85
84
|
"publishConfig": {
|
|
86
85
|
"access": "public"
|
|
87
|
-
},
|
|
88
|
-
"tap": {
|
|
89
|
-
"disable-coverage": true
|
|
90
86
|
}
|
|
91
87
|
}
|
package/test/404s.test.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { test } = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const fp = require('fastify-plugin')
|
|
5
5
|
const Fastify = require('fastify')
|
|
6
|
-
const sget = require('simple-get').concat
|
|
7
6
|
const expressPlugin = require('../index')
|
|
8
7
|
|
|
9
|
-
test('run hooks and middleware on default 404', t => {
|
|
10
|
-
t.plan(
|
|
8
|
+
test('run hooks and middleware on default 404', async t => {
|
|
9
|
+
t.plan(6)
|
|
11
10
|
|
|
12
11
|
const fastify = Fastify()
|
|
13
12
|
|
|
@@ -15,28 +14,28 @@ test('run hooks and middleware on default 404', t => {
|
|
|
15
14
|
.register(expressPlugin)
|
|
16
15
|
.after(() => {
|
|
17
16
|
fastify.use(function (_req, _res, next) {
|
|
18
|
-
t.
|
|
17
|
+
t.assert.ok('middleware called')
|
|
19
18
|
next()
|
|
20
19
|
})
|
|
21
20
|
})
|
|
22
21
|
|
|
23
22
|
fastify.addHook('onRequest', function (_req, _res, next) {
|
|
24
|
-
t.
|
|
23
|
+
t.assert.ok('onRequest called')
|
|
25
24
|
next()
|
|
26
25
|
})
|
|
27
26
|
|
|
28
27
|
fastify.addHook('preHandler', function (_request, _reply, next) {
|
|
29
|
-
t.
|
|
28
|
+
t.assert.ok('preHandler called')
|
|
30
29
|
next()
|
|
31
30
|
})
|
|
32
31
|
|
|
33
32
|
fastify.addHook('onSend', function (_request, _reply, _payload, next) {
|
|
34
|
-
t.
|
|
33
|
+
t.assert.ok('onSend called')
|
|
35
34
|
next()
|
|
36
35
|
})
|
|
37
36
|
|
|
38
37
|
fastify.addHook('onResponse', function (_request, _reply, next) {
|
|
39
|
-
t.
|
|
38
|
+
t.assert.ok('onResponse called')
|
|
40
39
|
next()
|
|
41
40
|
})
|
|
42
41
|
|
|
@@ -44,53 +43,48 @@ test('run hooks and middleware on default 404', t => {
|
|
|
44
43
|
reply.send({ hello: 'world' })
|
|
45
44
|
})
|
|
46
45
|
|
|
47
|
-
t.
|
|
46
|
+
t.after(() => fastify.close())
|
|
48
47
|
|
|
49
|
-
fastify.listen({ port: 0 }
|
|
50
|
-
t.error(err)
|
|
48
|
+
const address = await fastify.listen({ port: 0 })
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
body: JSON.stringify({ hello: 'world' }),
|
|
56
|
-
headers: { 'Content-Type': 'application/json' }
|
|
57
|
-
}, (err, response) => {
|
|
58
|
-
t.error(err)
|
|
59
|
-
t.equal(response.statusCode, 404)
|
|
60
|
-
})
|
|
50
|
+
const result = await fetch(address, {
|
|
51
|
+
method: 'PUT',
|
|
52
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
61
53
|
})
|
|
54
|
+
|
|
55
|
+
t.assert.deepStrictEqual(result.status, 404)
|
|
62
56
|
})
|
|
63
57
|
|
|
64
|
-
test('run non-encapsulated plugin hooks and middleware on default 404', t => {
|
|
65
|
-
t.plan(
|
|
58
|
+
test('run non-encapsulated plugin hooks and middleware on default 404', async t => {
|
|
59
|
+
t.plan(6)
|
|
66
60
|
|
|
67
61
|
const fastify = Fastify()
|
|
68
|
-
t.
|
|
62
|
+
t.after(() => fastify.close())
|
|
69
63
|
fastify.register(expressPlugin)
|
|
70
64
|
|
|
71
65
|
fastify.register(fp(function (instance, _options, next) {
|
|
72
66
|
instance.addHook('onRequest', function (_req, _res, next) {
|
|
73
|
-
t.
|
|
67
|
+
t.assert.ok('onRequest called')
|
|
74
68
|
next()
|
|
75
69
|
})
|
|
76
70
|
|
|
77
71
|
instance.use(function (_req, _res, next) {
|
|
78
|
-
t.
|
|
72
|
+
t.assert.ok('middleware called')
|
|
79
73
|
next()
|
|
80
74
|
})
|
|
81
75
|
|
|
82
76
|
instance.addHook('preHandler', function (_request, _reply, next) {
|
|
83
|
-
t.
|
|
77
|
+
t.assert.ok('preHandler called')
|
|
84
78
|
next()
|
|
85
79
|
})
|
|
86
80
|
|
|
87
81
|
instance.addHook('onSend', function (_request, _reply, _payload, next) {
|
|
88
|
-
t.
|
|
82
|
+
t.assert.ok('onSend called')
|
|
89
83
|
next()
|
|
90
84
|
})
|
|
91
85
|
|
|
92
86
|
instance.addHook('onResponse', function (_request, _reply, next) {
|
|
93
|
-
t.
|
|
87
|
+
t.assert.ok('onResponse called')
|
|
94
88
|
next()
|
|
95
89
|
})
|
|
96
90
|
|
|
@@ -101,50 +95,45 @@ test('run non-encapsulated plugin hooks and middleware on default 404', t => {
|
|
|
101
95
|
reply.send({ hello: 'world' })
|
|
102
96
|
})
|
|
103
97
|
|
|
104
|
-
fastify.listen({ port: 0 }
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
body: JSON.stringify({ hello: 'world' }),
|
|
110
|
-
headers: { 'Content-Type': 'application/json' }
|
|
111
|
-
}, (err, response) => {
|
|
112
|
-
t.error(err)
|
|
113
|
-
t.equal(response.statusCode, 404)
|
|
114
|
-
})
|
|
98
|
+
const address = await fastify.listen({ port: 0 })
|
|
99
|
+
|
|
100
|
+
const result = await fetch(address, {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
115
103
|
})
|
|
104
|
+
t.assert.deepStrictEqual(result.status, 404)
|
|
116
105
|
})
|
|
117
106
|
|
|
118
|
-
test('run non-encapsulated plugin hooks and middleware on custom 404', t => {
|
|
119
|
-
t.plan(
|
|
107
|
+
test('run non-encapsulated plugin hooks and middleware on custom 404', async t => {
|
|
108
|
+
t.plan(12)
|
|
120
109
|
|
|
121
110
|
const fastify = Fastify()
|
|
122
|
-
t.
|
|
111
|
+
t.after(() => fastify.close())
|
|
123
112
|
fastify.register(expressPlugin)
|
|
124
113
|
|
|
125
114
|
const plugin = fp((instance, _opts, next) => {
|
|
126
115
|
instance.addHook('onRequest', function (_req, _res, next) {
|
|
127
|
-
t.
|
|
116
|
+
t.assert.ok('onRequest called')
|
|
128
117
|
next()
|
|
129
118
|
})
|
|
130
119
|
|
|
131
120
|
instance.use(function (_req, _res, next) {
|
|
132
|
-
t.
|
|
121
|
+
t.assert.ok('middleware called')
|
|
133
122
|
next()
|
|
134
123
|
})
|
|
135
124
|
|
|
136
125
|
instance.addHook('preHandler', function (_request, _reply, next) {
|
|
137
|
-
t.
|
|
126
|
+
t.assert.ok('preHandler called')
|
|
138
127
|
next()
|
|
139
128
|
})
|
|
140
129
|
|
|
141
130
|
instance.addHook('onSend', function (_request, _reply, _payload, next) {
|
|
142
|
-
t.
|
|
131
|
+
t.assert.ok('onSend called')
|
|
143
132
|
next()
|
|
144
133
|
})
|
|
145
134
|
|
|
146
135
|
instance.addHook('onResponse', function (_request, _reply, next) {
|
|
147
|
-
t.
|
|
136
|
+
t.assert.ok('onResponse called')
|
|
148
137
|
next()
|
|
149
138
|
})
|
|
150
139
|
|
|
@@ -163,21 +152,16 @@ test('run non-encapsulated plugin hooks and middleware on custom 404', t => {
|
|
|
163
152
|
|
|
164
153
|
fastify.register(plugin) // Registering plugin after handler also works
|
|
165
154
|
|
|
166
|
-
fastify.listen({ port: 0 }
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
t.error(err)
|
|
173
|
-
t.equal(body.toString(), 'this was not found')
|
|
174
|
-
t.equal(response.statusCode, 404)
|
|
175
|
-
})
|
|
176
|
-
})
|
|
155
|
+
const address = await fastify.listen({ port: 0 })
|
|
156
|
+
|
|
157
|
+
const result = await fetch(address + '/not-found')
|
|
158
|
+
|
|
159
|
+
t.assert.deepStrictEqual(await result.text(), 'this was not found')
|
|
160
|
+
t.assert.deepStrictEqual(result.status, 404)
|
|
177
161
|
})
|
|
178
162
|
|
|
179
|
-
test('run hooks and middleware with encapsulated 404', t => {
|
|
180
|
-
t.plan(
|
|
163
|
+
test('run hooks and middleware with encapsulated 404', async t => {
|
|
164
|
+
t.plan(11)
|
|
181
165
|
|
|
182
166
|
const fastify = Fastify()
|
|
183
167
|
|
|
@@ -185,28 +169,28 @@ test('run hooks and middleware with encapsulated 404', t => {
|
|
|
185
169
|
.register(expressPlugin)
|
|
186
170
|
.after(() => {
|
|
187
171
|
fastify.use(function (_req, _res, next) {
|
|
188
|
-
t.
|
|
172
|
+
t.assert.ok('middleware called')
|
|
189
173
|
next()
|
|
190
174
|
})
|
|
191
175
|
})
|
|
192
176
|
|
|
193
177
|
fastify.addHook('onRequest', function (_req, _res, next) {
|
|
194
|
-
t.
|
|
178
|
+
t.assert.ok('onRequest called')
|
|
195
179
|
next()
|
|
196
180
|
})
|
|
197
181
|
|
|
198
182
|
fastify.addHook('preHandler', function (_request, _reply, next) {
|
|
199
|
-
t.
|
|
183
|
+
t.assert.ok('preHandler called')
|
|
200
184
|
next()
|
|
201
185
|
})
|
|
202
186
|
|
|
203
187
|
fastify.addHook('onSend', function (_request, _reply, _payload, next) {
|
|
204
|
-
t.
|
|
188
|
+
t.assert.ok('onSend called')
|
|
205
189
|
next()
|
|
206
190
|
})
|
|
207
191
|
|
|
208
192
|
fastify.addHook('onResponse', function (_request, _reply, next) {
|
|
209
|
-
t.
|
|
193
|
+
t.assert.ok('onResponse called')
|
|
210
194
|
next()
|
|
211
195
|
})
|
|
212
196
|
|
|
@@ -216,59 +200,54 @@ test('run hooks and middleware with encapsulated 404', t => {
|
|
|
216
200
|
})
|
|
217
201
|
|
|
218
202
|
f.addHook('onRequest', function (_req, _res, next) {
|
|
219
|
-
t.
|
|
203
|
+
t.assert.ok('onRequest 2 called')
|
|
220
204
|
next()
|
|
221
205
|
})
|
|
222
206
|
|
|
223
207
|
f.use(function (_req, _res, next) {
|
|
224
|
-
t.
|
|
208
|
+
t.assert.ok('middleware 2 called')
|
|
225
209
|
next()
|
|
226
210
|
})
|
|
227
211
|
|
|
228
212
|
f.addHook('preHandler', function (_request, _reply, next) {
|
|
229
|
-
t.
|
|
213
|
+
t.assert.ok('preHandler 2 called')
|
|
230
214
|
next()
|
|
231
215
|
})
|
|
232
216
|
|
|
233
217
|
f.addHook('onSend', function (_request, _reply, _payload, next) {
|
|
234
|
-
t.
|
|
218
|
+
t.assert.ok('onSend 2 called')
|
|
235
219
|
next()
|
|
236
220
|
})
|
|
237
221
|
|
|
238
222
|
f.addHook('onResponse', function (_request, _reply, next) {
|
|
239
|
-
t.
|
|
223
|
+
t.assert.ok('onResponse 2 called')
|
|
240
224
|
next()
|
|
241
225
|
})
|
|
242
226
|
|
|
243
227
|
next()
|
|
244
228
|
}, { prefix: '/test' })
|
|
245
229
|
|
|
246
|
-
t.
|
|
230
|
+
t.after(() => fastify.close())
|
|
247
231
|
|
|
248
|
-
fastify.listen({ port: 0 }
|
|
249
|
-
t.error(err)
|
|
232
|
+
const address = await fastify.listen({ port: 0 })
|
|
250
233
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
body: JSON.stringify({ hello: 'world' }),
|
|
255
|
-
headers: { 'Content-Type': 'application/json' }
|
|
256
|
-
}, (err, response) => {
|
|
257
|
-
t.error(err)
|
|
258
|
-
t.equal(response.statusCode, 404)
|
|
259
|
-
})
|
|
234
|
+
const result = await fetch(address + '/test', {
|
|
235
|
+
method: 'PUT',
|
|
236
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
260
237
|
})
|
|
238
|
+
|
|
239
|
+
t.assert.deepStrictEqual(result.status, 404)
|
|
261
240
|
})
|
|
262
241
|
|
|
263
|
-
test('run middlewares on default 404', t => {
|
|
264
|
-
t.plan(
|
|
242
|
+
test('run middlewares on default 404', async t => {
|
|
243
|
+
t.plan(2)
|
|
265
244
|
|
|
266
245
|
const fastify = Fastify()
|
|
267
246
|
fastify
|
|
268
247
|
.register(expressPlugin)
|
|
269
248
|
.after(() => {
|
|
270
249
|
fastify.use(function (_req, _res, next) {
|
|
271
|
-
t.
|
|
250
|
+
t.assert.ok('middleware called')
|
|
272
251
|
next()
|
|
273
252
|
})
|
|
274
253
|
})
|
|
@@ -277,32 +256,27 @@ test('run middlewares on default 404', t => {
|
|
|
277
256
|
reply.send({ hello: 'world' })
|
|
278
257
|
})
|
|
279
258
|
|
|
280
|
-
t.
|
|
259
|
+
t.after(() => fastify.close())
|
|
281
260
|
|
|
282
|
-
fastify.listen({ port: 0 }
|
|
283
|
-
t.error(err)
|
|
261
|
+
const address = await fastify.listen({ port: 0 })
|
|
284
262
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
body: JSON.stringify({ hello: 'world' }),
|
|
289
|
-
headers: { 'Content-Type': 'application/json' }
|
|
290
|
-
}, (err, response) => {
|
|
291
|
-
t.error(err)
|
|
292
|
-
t.equal(response.statusCode, 404)
|
|
293
|
-
})
|
|
263
|
+
const result = await fetch(address, {
|
|
264
|
+
method: 'PUT',
|
|
265
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
294
266
|
})
|
|
267
|
+
|
|
268
|
+
t.assert.deepStrictEqual(result.status, 404)
|
|
295
269
|
})
|
|
296
270
|
|
|
297
|
-
test('run middlewares with encapsulated 404', t => {
|
|
298
|
-
t.plan(
|
|
271
|
+
test('run middlewares with encapsulated 404', async t => {
|
|
272
|
+
t.plan(3)
|
|
299
273
|
|
|
300
274
|
const fastify = Fastify()
|
|
301
275
|
fastify
|
|
302
276
|
.register(expressPlugin)
|
|
303
277
|
.after(() => {
|
|
304
278
|
fastify.use(function (_req, _res, next) {
|
|
305
|
-
t.
|
|
279
|
+
t.assert.ok('middleware called')
|
|
306
280
|
next()
|
|
307
281
|
})
|
|
308
282
|
})
|
|
@@ -313,26 +287,21 @@ test('run middlewares with encapsulated 404', t => {
|
|
|
313
287
|
})
|
|
314
288
|
|
|
315
289
|
f.use(function (_req, _res, next) {
|
|
316
|
-
t.
|
|
290
|
+
t.assert.ok('middleware 2 called')
|
|
317
291
|
next()
|
|
318
292
|
})
|
|
319
293
|
|
|
320
294
|
next()
|
|
321
295
|
}, { prefix: '/test' })
|
|
322
296
|
|
|
323
|
-
t.
|
|
297
|
+
t.after(() => fastify.close())
|
|
324
298
|
|
|
325
|
-
fastify.listen({ port: 0 }
|
|
326
|
-
t.error(err)
|
|
299
|
+
const address = await fastify.listen({ port: 0 })
|
|
327
300
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
body: JSON.stringify({ hello: 'world' }),
|
|
332
|
-
headers: { 'Content-Type': 'application/json' }
|
|
333
|
-
}, (err, response) => {
|
|
334
|
-
t.error(err)
|
|
335
|
-
t.equal(response.statusCode, 404)
|
|
336
|
-
})
|
|
301
|
+
const result = await fetch(address + '/test', {
|
|
302
|
+
method: 'PUT',
|
|
303
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
337
304
|
})
|
|
305
|
+
|
|
306
|
+
t.assert.deepStrictEqual(result.status, 404)
|
|
338
307
|
})
|