@fastify/express 1.1.0 → 2.0.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/.github/workflows/nodejs.yml +8 -40
- package/README.md +7 -8
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/package.json +6 -9
- package/test/404s.test.js +17 -17
- package/test/application.test.js +14 -14
- package/test/basic.test.js +37 -37
- package/test/enhance-request.test.js +12 -12
- package/test/form-data.test.js +16 -16
- package/test/hooks.test.js +3 -3
- package/test/middleware.test.js +32 -32
|
@@ -1,49 +1,17 @@
|
|
|
1
1
|
name: CI
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
on:
|
|
3
4
|
push:
|
|
4
5
|
paths-ignore:
|
|
5
|
-
- docs/**
|
|
6
|
+
- 'docs/**'
|
|
6
7
|
- '*.md'
|
|
7
8
|
pull_request:
|
|
8
9
|
paths-ignore:
|
|
9
|
-
- docs/**
|
|
10
|
+
- 'docs/**'
|
|
10
11
|
- '*.md'
|
|
12
|
+
|
|
11
13
|
jobs:
|
|
12
14
|
test:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
node-version:
|
|
17
|
-
- 10
|
|
18
|
-
- 12
|
|
19
|
-
- 14
|
|
20
|
-
- 16
|
|
21
|
-
os:
|
|
22
|
-
- macos-latest
|
|
23
|
-
- ubuntu-latest
|
|
24
|
-
- windows-latest
|
|
25
|
-
steps:
|
|
26
|
-
- uses: actions/checkout@v3
|
|
27
|
-
- name: Use Node.js
|
|
28
|
-
uses: actions/setup-node@v3
|
|
29
|
-
with:
|
|
30
|
-
node-version: ${{ matrix.node-version }}
|
|
31
|
-
- name: Install Dependencies
|
|
32
|
-
run: |
|
|
33
|
-
npm install --ignore-scripts
|
|
34
|
-
- name: Run Tests
|
|
35
|
-
run: |
|
|
36
|
-
npm test
|
|
37
|
-
automerge:
|
|
38
|
-
needs: test
|
|
39
|
-
runs-on: ubuntu-latest
|
|
40
|
-
permissions:
|
|
41
|
-
pull-requests: write
|
|
42
|
-
contents: write
|
|
43
|
-
steps:
|
|
44
|
-
- uses: fastify/github-action-merge-dependabot@v3
|
|
45
|
-
if: >-
|
|
46
|
-
${{ github.actor == 'dependabot[bot]' && github.event_name ==
|
|
47
|
-
'pull_request' }}
|
|
48
|
-
with:
|
|
49
|
-
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
15
|
+
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
|
|
16
|
+
with:
|
|
17
|
+
license-check: true
|
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
[](https://www.npmjs.com/package/@fastify/express)
|
|
5
|
-
[](https://snyk.io/test/github/fastify/fastify-express)
|
|
6
5
|
[](https://standardjs.com/)
|
|
7
6
|
|
|
8
7
|
This plugin adds full [Express](http://expressjs.com) compatibility to Fastify, it exposes the same `use` function of Express, and it allows you to use any Express middleware or application.<br/>
|
|
@@ -41,7 +40,7 @@ async function build () {
|
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
build()
|
|
44
|
-
.then(fastify => fastify.listen(3000))
|
|
43
|
+
.then(fastify => fastify.listen({ port: 3000 }))
|
|
45
44
|
.catch(console.log)
|
|
46
45
|
```
|
|
47
46
|
|
|
@@ -93,7 +92,7 @@ fastify.register(require('@fastify/express'))
|
|
|
93
92
|
fastify.use(router)
|
|
94
93
|
})
|
|
95
94
|
|
|
96
|
-
fastify.listen(3000, console.log)
|
|
95
|
+
fastify.listen({ port: 3000 }, console.log)
|
|
97
96
|
```
|
|
98
97
|
|
|
99
98
|
#### Testing Your App
|
|
@@ -222,7 +221,7 @@ Example application:
|
|
|
222
221
|
```js
|
|
223
222
|
const Fastify = require('fastify')
|
|
224
223
|
const Express = require('express')
|
|
225
|
-
const expressPlugin = require('fastify
|
|
224
|
+
const expressPlugin = require('@fastify/express')
|
|
226
225
|
const bodyParser = require('body-parser')
|
|
227
226
|
|
|
228
227
|
const fastify = Fastify()
|
|
@@ -240,21 +239,21 @@ fastify.post('/hello', (req, reply) => {
|
|
|
240
239
|
})
|
|
241
240
|
```
|
|
242
241
|
|
|
243
|
-
For this case, you need to remove `body-parser`, install
|
|
242
|
+
For this case, you need to remove `body-parser`, install `@fastify/formbody` and change `@fastify/express` options:
|
|
244
243
|
|
|
245
244
|
|
|
246
245
|
```js
|
|
247
246
|
const Fastify = require('fastify')
|
|
248
247
|
const Express = require('express')
|
|
249
|
-
const expressPlugin = require('fastify
|
|
250
|
-
const fastifyFormBody = require('fastify
|
|
248
|
+
const expressPlugin = require('@fastify/express')
|
|
249
|
+
const fastifyFormBody = require('@fastify/formbody')
|
|
251
250
|
|
|
252
251
|
const fastify = Fastify()
|
|
253
252
|
const express = Express()
|
|
254
253
|
|
|
255
254
|
await fastify.register(fastifyFormBody)
|
|
256
255
|
await fastify.register(expressPlugin, {
|
|
257
|
-
// run express after
|
|
256
|
+
// run express after `@fastify/formbody` logic
|
|
258
257
|
expressHook: 'preHandler'
|
|
259
258
|
})
|
|
260
259
|
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/express",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Express compatibility layer for Fastify",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -29,23 +29,20 @@
|
|
|
29
29
|
"@types/node": "*",
|
|
30
30
|
"body-parser": "^1.20.0",
|
|
31
31
|
"cors": "^2.8.5",
|
|
32
|
-
"fastify": "^
|
|
33
|
-
"fastify
|
|
32
|
+
"fastify": "^4.0.0-rc.3",
|
|
33
|
+
"@fastify/formbody": "^7.0.1",
|
|
34
34
|
"helmet": "^5.0.0",
|
|
35
|
-
"passport": "^0.
|
|
35
|
+
"passport": "^0.6.0",
|
|
36
36
|
"passport-http-bearer": "^1.0.1",
|
|
37
37
|
"serve-static": "^1.14.1",
|
|
38
38
|
"simple-get": "^4.0.0",
|
|
39
39
|
"standard": "^17.0.0",
|
|
40
40
|
"tap": "^16.0.0",
|
|
41
|
-
"tsd": "^0.
|
|
41
|
+
"tsd": "^0.22.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"express": "^4.17.1",
|
|
45
|
-
"fastify-plugin": "^
|
|
46
|
-
},
|
|
47
|
-
"engines": {
|
|
48
|
-
"node": ">=10.0.0"
|
|
45
|
+
"fastify-plugin": "^4.0.0"
|
|
49
46
|
},
|
|
50
47
|
"tsd": {
|
|
51
48
|
"directory": "test/types"
|
package/test/404s.test.js
CHANGED
|
@@ -44,9 +44,9 @@ test('run hooks and middleware on default 404', t => {
|
|
|
44
44
|
reply.send({ hello: 'world' })
|
|
45
45
|
})
|
|
46
46
|
|
|
47
|
-
t.
|
|
47
|
+
t.teardown(fastify.close.bind(fastify))
|
|
48
48
|
|
|
49
|
-
fastify.listen(0, err => {
|
|
49
|
+
fastify.listen({ port: 0 }, err => {
|
|
50
50
|
t.error(err)
|
|
51
51
|
|
|
52
52
|
sget({
|
|
@@ -56,7 +56,7 @@ test('run hooks and middleware on default 404', t => {
|
|
|
56
56
|
headers: { 'Content-Type': 'application/json' }
|
|
57
57
|
}, (err, response, body) => {
|
|
58
58
|
t.error(err)
|
|
59
|
-
t.
|
|
59
|
+
t.equal(response.statusCode, 404)
|
|
60
60
|
})
|
|
61
61
|
})
|
|
62
62
|
})
|
|
@@ -101,7 +101,7 @@ test('run non-encapsulated plugin hooks and middleware on default 404', t => {
|
|
|
101
101
|
reply.send({ hello: 'world' })
|
|
102
102
|
})
|
|
103
103
|
|
|
104
|
-
fastify.listen(0, (err, address) => {
|
|
104
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
105
105
|
t.error(err)
|
|
106
106
|
sget({
|
|
107
107
|
method: 'POST',
|
|
@@ -110,7 +110,7 @@ test('run non-encapsulated plugin hooks and middleware on default 404', t => {
|
|
|
110
110
|
headers: { 'Content-Type': 'application/json' }
|
|
111
111
|
}, (err, response, body) => {
|
|
112
112
|
t.error(err)
|
|
113
|
-
t.
|
|
113
|
+
t.equal(response.statusCode, 404)
|
|
114
114
|
})
|
|
115
115
|
})
|
|
116
116
|
})
|
|
@@ -163,15 +163,15 @@ test('run non-encapsulated plugin hooks and middleware on custom 404', t => {
|
|
|
163
163
|
|
|
164
164
|
fastify.register(plugin) // Registering plugin after handler also works
|
|
165
165
|
|
|
166
|
-
fastify.listen(0, (err, address) => {
|
|
166
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
167
167
|
t.error(err)
|
|
168
168
|
sget({
|
|
169
169
|
method: 'GET',
|
|
170
170
|
url: address + '/not-found'
|
|
171
171
|
}, (err, response, body) => {
|
|
172
172
|
t.error(err)
|
|
173
|
-
t.
|
|
174
|
-
t.
|
|
173
|
+
t.equal(body.toString(), 'this was not found')
|
|
174
|
+
t.equal(response.statusCode, 404)
|
|
175
175
|
})
|
|
176
176
|
})
|
|
177
177
|
})
|
|
@@ -243,9 +243,9 @@ test('run hooks and middleware with encapsulated 404', t => {
|
|
|
243
243
|
next()
|
|
244
244
|
}, { prefix: '/test' })
|
|
245
245
|
|
|
246
|
-
t.
|
|
246
|
+
t.teardown(fastify.close.bind(fastify))
|
|
247
247
|
|
|
248
|
-
fastify.listen(0, err => {
|
|
248
|
+
fastify.listen({ port: 0 }, err => {
|
|
249
249
|
t.error(err)
|
|
250
250
|
|
|
251
251
|
sget({
|
|
@@ -255,7 +255,7 @@ test('run hooks and middleware with encapsulated 404', t => {
|
|
|
255
255
|
headers: { 'Content-Type': 'application/json' }
|
|
256
256
|
}, (err, response, body) => {
|
|
257
257
|
t.error(err)
|
|
258
|
-
t.
|
|
258
|
+
t.equal(response.statusCode, 404)
|
|
259
259
|
})
|
|
260
260
|
})
|
|
261
261
|
})
|
|
@@ -277,9 +277,9 @@ test('run middlewares on default 404', t => {
|
|
|
277
277
|
reply.send({ hello: 'world' })
|
|
278
278
|
})
|
|
279
279
|
|
|
280
|
-
t.
|
|
280
|
+
t.teardown(fastify.close.bind(fastify))
|
|
281
281
|
|
|
282
|
-
fastify.listen(0, err => {
|
|
282
|
+
fastify.listen({ port: 0 }, err => {
|
|
283
283
|
t.error(err)
|
|
284
284
|
|
|
285
285
|
sget({
|
|
@@ -289,7 +289,7 @@ test('run middlewares on default 404', t => {
|
|
|
289
289
|
headers: { 'Content-Type': 'application/json' }
|
|
290
290
|
}, (err, response, body) => {
|
|
291
291
|
t.error(err)
|
|
292
|
-
t.
|
|
292
|
+
t.equal(response.statusCode, 404)
|
|
293
293
|
})
|
|
294
294
|
})
|
|
295
295
|
})
|
|
@@ -320,9 +320,9 @@ test('run middlewares with encapsulated 404', t => {
|
|
|
320
320
|
next()
|
|
321
321
|
}, { prefix: '/test' })
|
|
322
322
|
|
|
323
|
-
t.
|
|
323
|
+
t.teardown(fastify.close.bind(fastify))
|
|
324
324
|
|
|
325
|
-
fastify.listen(0, err => {
|
|
325
|
+
fastify.listen({ port: 0 }, err => {
|
|
326
326
|
t.error(err)
|
|
327
327
|
|
|
328
328
|
sget({
|
|
@@ -332,7 +332,7 @@ test('run middlewares with encapsulated 404', t => {
|
|
|
332
332
|
headers: { 'Content-Type': 'application/json' }
|
|
333
333
|
}, (err, response, body) => {
|
|
334
334
|
t.error(err)
|
|
335
|
-
t.
|
|
335
|
+
t.equal(response.statusCode, 404)
|
|
336
336
|
})
|
|
337
337
|
})
|
|
338
338
|
})
|
package/test/application.test.js
CHANGED
|
@@ -26,16 +26,16 @@ test('Register express application', t => {
|
|
|
26
26
|
fastify.register(expressPlugin)
|
|
27
27
|
.after(() => { fastify.use(express) })
|
|
28
28
|
|
|
29
|
-
fastify.listen(0, (err, address) => {
|
|
29
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
30
30
|
t.error(err)
|
|
31
31
|
sget({
|
|
32
32
|
method: 'GET',
|
|
33
33
|
url: address + '/hello'
|
|
34
34
|
}, (err, res, data) => {
|
|
35
35
|
t.error(err)
|
|
36
|
-
t.
|
|
36
|
+
t.equal(res.statusCode, 201)
|
|
37
37
|
t.match(res.headers, { 'x-custom': 'true' })
|
|
38
|
-
t.
|
|
38
|
+
t.same(JSON.parse(data), { hello: 'world' })
|
|
39
39
|
})
|
|
40
40
|
})
|
|
41
41
|
})
|
|
@@ -65,25 +65,25 @@ test('Register express application that uses Router', t => {
|
|
|
65
65
|
fastify.register(expressPlugin)
|
|
66
66
|
.after(() => { fastify.use(router) })
|
|
67
67
|
|
|
68
|
-
fastify.listen(0, (err, address) => {
|
|
68
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
69
69
|
t.error(err)
|
|
70
70
|
sget({
|
|
71
71
|
method: 'GET',
|
|
72
72
|
url: address + '/hello'
|
|
73
73
|
}, (err, res, data) => {
|
|
74
74
|
t.error(err)
|
|
75
|
-
t.
|
|
75
|
+
t.equal(res.statusCode, 201)
|
|
76
76
|
t.match(res.headers, { 'x-custom': 'true' })
|
|
77
|
-
t.
|
|
77
|
+
t.same(JSON.parse(data), { hello: 'world' })
|
|
78
78
|
})
|
|
79
79
|
sget({
|
|
80
80
|
method: 'GET',
|
|
81
81
|
url: address + '/foo'
|
|
82
82
|
}, (err, res, data) => {
|
|
83
83
|
t.error(err)
|
|
84
|
-
t.
|
|
84
|
+
t.equal(res.statusCode, 400)
|
|
85
85
|
t.match(res.headers, { 'x-custom': 'true' })
|
|
86
|
-
t.
|
|
86
|
+
t.same(JSON.parse(data), { foo: 'bar' })
|
|
87
87
|
})
|
|
88
88
|
})
|
|
89
89
|
})
|
|
@@ -104,14 +104,14 @@ test('Should remove x-powered-by header', t => {
|
|
|
104
104
|
.register(expressPlugin)
|
|
105
105
|
.after(() => { fastify.use(router) })
|
|
106
106
|
|
|
107
|
-
fastify.listen(0, (err, address) => {
|
|
107
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
108
108
|
t.error(err)
|
|
109
109
|
sget({
|
|
110
110
|
method: 'GET',
|
|
111
111
|
url: address
|
|
112
112
|
}, (err, res) => {
|
|
113
113
|
t.error(err)
|
|
114
|
-
t.
|
|
114
|
+
t.equal(res.headers['x-powered-by'], undefined)
|
|
115
115
|
})
|
|
116
116
|
})
|
|
117
117
|
})
|
|
@@ -132,14 +132,14 @@ test('Should expose the express app on the fastify instance', t => {
|
|
|
132
132
|
.register(expressPlugin)
|
|
133
133
|
.after(() => { fastify.use(router) })
|
|
134
134
|
|
|
135
|
-
fastify.listen(0, (err, address) => {
|
|
135
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
136
136
|
t.error(err)
|
|
137
137
|
sget({
|
|
138
138
|
method: 'GET',
|
|
139
139
|
url: address
|
|
140
140
|
}, (err, res) => {
|
|
141
141
|
t.error(err)
|
|
142
|
-
t.
|
|
142
|
+
t.equal(fastify.express.disabled('x-powered-by'), true)
|
|
143
143
|
})
|
|
144
144
|
})
|
|
145
145
|
})
|
|
@@ -166,14 +166,14 @@ test('Should flush headers if express handles request', t => {
|
|
|
166
166
|
.register(expressPlugin)
|
|
167
167
|
.after(() => { fastify.use(router) })
|
|
168
168
|
|
|
169
|
-
fastify.listen(0, (err, address) => {
|
|
169
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
170
170
|
t.error(err)
|
|
171
171
|
sget({
|
|
172
172
|
method: 'GET',
|
|
173
173
|
url: address
|
|
174
174
|
}, (err, res) => {
|
|
175
175
|
t.error(err)
|
|
176
|
-
t.
|
|
176
|
+
t.equal(res.headers.foo, 'bar')
|
|
177
177
|
})
|
|
178
178
|
})
|
|
179
179
|
})
|
package/test/basic.test.js
CHANGED
|
@@ -22,7 +22,7 @@ test('Should support connect style middlewares', t => {
|
|
|
22
22
|
return { hello: 'world' }
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
fastify.listen(0, (err, address) => {
|
|
25
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
26
26
|
t.error(err)
|
|
27
27
|
sget({
|
|
28
28
|
method: 'GET',
|
|
@@ -32,7 +32,7 @@ test('Should support connect style middlewares', t => {
|
|
|
32
32
|
t.match(res.headers, {
|
|
33
33
|
'access-control-allow-origin': '*'
|
|
34
34
|
})
|
|
35
|
-
t.
|
|
35
|
+
t.same(JSON.parse(data), { hello: 'world' })
|
|
36
36
|
})
|
|
37
37
|
})
|
|
38
38
|
})
|
|
@@ -49,7 +49,7 @@ test('Should support connect style middlewares (async await)', async t => {
|
|
|
49
49
|
return { hello: 'world' }
|
|
50
50
|
})
|
|
51
51
|
|
|
52
|
-
const address = await fastify.listen(0)
|
|
52
|
+
const address = await fastify.listen({ port: 0 })
|
|
53
53
|
return new Promise((resolve, reject) => {
|
|
54
54
|
sget({
|
|
55
55
|
method: 'GET',
|
|
@@ -59,7 +59,7 @@ test('Should support connect style middlewares (async await)', async t => {
|
|
|
59
59
|
t.match(res.headers, {
|
|
60
60
|
'access-control-allow-origin': '*'
|
|
61
61
|
})
|
|
62
|
-
t.
|
|
62
|
+
t.same(JSON.parse(data), { hello: 'world' })
|
|
63
63
|
resolve()
|
|
64
64
|
})
|
|
65
65
|
})
|
|
@@ -78,7 +78,7 @@ test('Should support connect style middlewares (async await after)', async t =>
|
|
|
78
78
|
return { hello: 'world' }
|
|
79
79
|
})
|
|
80
80
|
|
|
81
|
-
const address = await fastify.listen(0)
|
|
81
|
+
const address = await fastify.listen({ port: 0 })
|
|
82
82
|
return new Promise((resolve, reject) => {
|
|
83
83
|
sget({
|
|
84
84
|
method: 'GET',
|
|
@@ -88,7 +88,7 @@ test('Should support connect style middlewares (async await after)', async t =>
|
|
|
88
88
|
t.match(res.headers, {
|
|
89
89
|
'access-control-allow-origin': '*'
|
|
90
90
|
})
|
|
91
|
-
t.
|
|
91
|
+
t.same(JSON.parse(data), { hello: 'world' })
|
|
92
92
|
resolve()
|
|
93
93
|
})
|
|
94
94
|
})
|
|
@@ -111,7 +111,7 @@ test('Should support per path middlewares', t => {
|
|
|
111
111
|
return { hello: 'world' }
|
|
112
112
|
})
|
|
113
113
|
|
|
114
|
-
fastify.listen(0, (err, address) => {
|
|
114
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
115
115
|
t.error(err)
|
|
116
116
|
sget({
|
|
117
117
|
method: 'GET',
|
|
@@ -139,7 +139,7 @@ test('Should support complex middlewares', t => {
|
|
|
139
139
|
const fastify = Fastify()
|
|
140
140
|
|
|
141
141
|
passport.use(new Strategy((token, cb) => {
|
|
142
|
-
t.
|
|
142
|
+
t.equal(token, '123456789')
|
|
143
143
|
cb(null, { token })
|
|
144
144
|
}))
|
|
145
145
|
|
|
@@ -148,10 +148,10 @@ test('Should support complex middlewares', t => {
|
|
|
148
148
|
.after(() => { fastify.use(passport.authenticate('bearer', { session: false })) })
|
|
149
149
|
fastify
|
|
150
150
|
.get('/', (req, reply) => {
|
|
151
|
-
t.
|
|
151
|
+
t.same(req.raw.user, { token: '123456789' })
|
|
152
152
|
reply.send('ok')
|
|
153
153
|
})
|
|
154
|
-
.listen(0, (err, address) => {
|
|
154
|
+
.listen({ port: 0 }, (err, address) => {
|
|
155
155
|
t.error(err)
|
|
156
156
|
sget({
|
|
157
157
|
method: 'GET',
|
|
@@ -186,7 +186,7 @@ test('Encapsulation support / 1', t => {
|
|
|
186
186
|
reply.send('ok')
|
|
187
187
|
})
|
|
188
188
|
|
|
189
|
-
fastify.listen(0, (err, address) => {
|
|
189
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
190
190
|
t.error(err)
|
|
191
191
|
sget({
|
|
192
192
|
method: 'GET',
|
|
@@ -222,7 +222,7 @@ test('Encapsulation support / 2', t => {
|
|
|
222
222
|
reply.send('ok')
|
|
223
223
|
})
|
|
224
224
|
|
|
225
|
-
fastify.listen(0, (err, address) => {
|
|
225
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
226
226
|
t.error(err)
|
|
227
227
|
sget({
|
|
228
228
|
method: 'GET',
|
|
@@ -260,7 +260,7 @@ test('Encapsulation support / 3', t => {
|
|
|
260
260
|
reply.send('ok')
|
|
261
261
|
})
|
|
262
262
|
|
|
263
|
-
fastify.listen(0, (err, address) => {
|
|
263
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
264
264
|
t.error(err)
|
|
265
265
|
sget({
|
|
266
266
|
method: 'GET',
|
|
@@ -309,7 +309,7 @@ test('Encapsulation support / 4', t => {
|
|
|
309
309
|
reply.send('ok')
|
|
310
310
|
})
|
|
311
311
|
|
|
312
|
-
fastify.listen(0, (err, address) => {
|
|
312
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
313
313
|
t.error(err)
|
|
314
314
|
sget({
|
|
315
315
|
method: 'GET',
|
|
@@ -378,7 +378,7 @@ test('Encapsulation support / 5', t => {
|
|
|
378
378
|
reply.send('ok')
|
|
379
379
|
})
|
|
380
380
|
|
|
381
|
-
fastify.listen(0, (err, address) => {
|
|
381
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
382
382
|
t.error(err)
|
|
383
383
|
sget({
|
|
384
384
|
method: 'GET',
|
|
@@ -449,7 +449,7 @@ test('Middleware chain', t => {
|
|
|
449
449
|
return { hello: 'world' }
|
|
450
450
|
})
|
|
451
451
|
|
|
452
|
-
fastify.listen(0, (err, address) => {
|
|
452
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
453
453
|
t.error(err)
|
|
454
454
|
sget({
|
|
455
455
|
method: 'GET',
|
|
@@ -461,17 +461,17 @@ test('Middleware chain', t => {
|
|
|
461
461
|
})
|
|
462
462
|
|
|
463
463
|
function middleware1 (req, res, next) {
|
|
464
|
-
t.
|
|
464
|
+
t.equal(order.shift(), 1)
|
|
465
465
|
next()
|
|
466
466
|
}
|
|
467
467
|
|
|
468
468
|
function middleware2 (req, res, next) {
|
|
469
|
-
t.
|
|
469
|
+
t.equal(order.shift(), 2)
|
|
470
470
|
next()
|
|
471
471
|
}
|
|
472
472
|
|
|
473
473
|
function middleware3 (req, res, next) {
|
|
474
|
-
t.
|
|
474
|
+
t.equal(order.shift(), 3)
|
|
475
475
|
next()
|
|
476
476
|
}
|
|
477
477
|
})
|
|
@@ -495,32 +495,32 @@ test('Middleware chain (with errors) / 1', t => {
|
|
|
495
495
|
return { hello: 'world' }
|
|
496
496
|
})
|
|
497
497
|
|
|
498
|
-
fastify.listen(0, (err, address) => {
|
|
498
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
499
499
|
t.error(err)
|
|
500
500
|
sget({
|
|
501
501
|
method: 'GET',
|
|
502
502
|
url: address
|
|
503
503
|
}, (err, res, data) => {
|
|
504
504
|
t.error(err)
|
|
505
|
-
t.
|
|
505
|
+
t.equal(res.statusCode, 500)
|
|
506
506
|
fastify.close()
|
|
507
507
|
})
|
|
508
508
|
})
|
|
509
509
|
|
|
510
510
|
function middleware1 (req, res, next) {
|
|
511
|
-
t.
|
|
511
|
+
t.equal(order.shift(), 1)
|
|
512
512
|
next(new Error('middleware1'))
|
|
513
513
|
}
|
|
514
514
|
|
|
515
515
|
function middleware2 (err, req, res, next) {
|
|
516
|
-
t.
|
|
517
|
-
t.
|
|
516
|
+
t.equal(err.message, 'middleware1')
|
|
517
|
+
t.equal(order.shift(), 2)
|
|
518
518
|
next(new Error('middleware2'))
|
|
519
519
|
}
|
|
520
520
|
|
|
521
521
|
function middleware3 (err, req, res, next) {
|
|
522
|
-
t.
|
|
523
|
-
t.
|
|
522
|
+
t.equal(err.message, 'middleware2')
|
|
523
|
+
t.equal(order.shift(), 3)
|
|
524
524
|
next(new Error('kaboom'))
|
|
525
525
|
}
|
|
526
526
|
})
|
|
@@ -532,7 +532,7 @@ test('Middleware chain (with errors) / 2', t => {
|
|
|
532
532
|
const fastify = Fastify()
|
|
533
533
|
|
|
534
534
|
fastify.setErrorHandler((err, req, reply) => {
|
|
535
|
-
t.
|
|
535
|
+
t.equal(err.message, 'middleware2')
|
|
536
536
|
reply.send(err)
|
|
537
537
|
})
|
|
538
538
|
|
|
@@ -549,26 +549,26 @@ test('Middleware chain (with errors) / 2', t => {
|
|
|
549
549
|
return { hello: 'world' }
|
|
550
550
|
})
|
|
551
551
|
|
|
552
|
-
fastify.listen(0, (err, address) => {
|
|
552
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
553
553
|
t.error(err)
|
|
554
554
|
sget({
|
|
555
555
|
method: 'GET',
|
|
556
556
|
url: address
|
|
557
557
|
}, (err, res, data) => {
|
|
558
558
|
t.error(err)
|
|
559
|
-
t.
|
|
559
|
+
t.equal(res.statusCode, 500)
|
|
560
560
|
fastify.close()
|
|
561
561
|
})
|
|
562
562
|
})
|
|
563
563
|
|
|
564
564
|
function middleware1 (req, res, next) {
|
|
565
|
-
t.
|
|
565
|
+
t.equal(order.shift(), 1)
|
|
566
566
|
next(new Error('middleware1'))
|
|
567
567
|
}
|
|
568
568
|
|
|
569
569
|
function middleware2 (err, req, res, next) {
|
|
570
|
-
t.
|
|
571
|
-
t.
|
|
570
|
+
t.equal(err.message, 'middleware1')
|
|
571
|
+
t.equal(order.shift(), 2)
|
|
572
572
|
next(new Error('middleware2'))
|
|
573
573
|
}
|
|
574
574
|
|
|
@@ -615,7 +615,7 @@ test('Send a response from a middleware', t => {
|
|
|
615
615
|
t.fail('We should not be here')
|
|
616
616
|
})
|
|
617
617
|
|
|
618
|
-
fastify.listen(0, (err, address) => {
|
|
618
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
619
619
|
t.error(err)
|
|
620
620
|
sget({
|
|
621
621
|
method: 'GET',
|
|
@@ -623,7 +623,7 @@ test('Send a response from a middleware', t => {
|
|
|
623
623
|
json: true
|
|
624
624
|
}, (err, res, data) => {
|
|
625
625
|
t.error(err)
|
|
626
|
-
t.
|
|
626
|
+
t.same(data, { hello: 'world' })
|
|
627
627
|
fastify.close()
|
|
628
628
|
})
|
|
629
629
|
})
|
|
@@ -657,15 +657,15 @@ test('Should support plugin level prefix', t => {
|
|
|
657
657
|
next()
|
|
658
658
|
}, { prefix: '/hello' })
|
|
659
659
|
|
|
660
|
-
fastify.listen(0, (err, address) => {
|
|
660
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
661
661
|
t.error(err)
|
|
662
662
|
sget({
|
|
663
663
|
method: 'GET',
|
|
664
664
|
url: address + '/hello/world'
|
|
665
665
|
}, (err, res, data) => {
|
|
666
666
|
t.error(err)
|
|
667
|
-
t.
|
|
668
|
-
t.
|
|
667
|
+
t.equal(res.headers['x-foo'], 'bar')
|
|
668
|
+
t.same(JSON.parse(data), { hello: 'world' })
|
|
669
669
|
})
|
|
670
670
|
})
|
|
671
671
|
})
|
|
@@ -14,18 +14,18 @@ test('Should enhance the Node.js core request/response objects', t => {
|
|
|
14
14
|
fastify.register(expressPlugin)
|
|
15
15
|
|
|
16
16
|
fastify.get('/', async (req, reply) => {
|
|
17
|
-
t.
|
|
18
|
-
t.
|
|
19
|
-
t.
|
|
20
|
-
t.
|
|
21
|
-
t.
|
|
22
|
-
t.
|
|
17
|
+
t.equal(req.raw.originalUrl, req.raw.url)
|
|
18
|
+
t.equal(req.raw.id, req.id)
|
|
19
|
+
t.equal(req.raw.hostname, req.hostname)
|
|
20
|
+
t.equal(req.raw.protocol, req.protocol)
|
|
21
|
+
t.equal(req.raw.ip, req.ip)
|
|
22
|
+
t.same(req.raw.ips, req.ips)
|
|
23
23
|
t.ok(req.raw.log)
|
|
24
24
|
t.ok(reply.raw.log)
|
|
25
25
|
return { hello: 'world' }
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
fastify.listen(0, (err, address) => {
|
|
28
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
29
29
|
t.error(err)
|
|
30
30
|
sget({
|
|
31
31
|
method: 'GET',
|
|
@@ -40,19 +40,19 @@ test('trust proxy protocol', (t) => {
|
|
|
40
40
|
t.plan(5)
|
|
41
41
|
const fastify = Fastify({ trustProxy: true })
|
|
42
42
|
|
|
43
|
-
t.
|
|
43
|
+
t.teardown(fastify.close.bind(fastify))
|
|
44
44
|
|
|
45
45
|
fastify.register(expressPlugin).after(() => {
|
|
46
46
|
fastify.use('/', function (req, res) {
|
|
47
|
-
t.
|
|
48
|
-
t.
|
|
49
|
-
t.
|
|
47
|
+
t.equal(req.ip, '1.1.1.1', 'gets ip from x-forwarded-for')
|
|
48
|
+
t.equal(req.hostname, 'example.com', 'gets hostname from x-forwarded-host')
|
|
49
|
+
t.equal(req.protocol, 'lorem', 'gets protocol from x-forwarded-proto')
|
|
50
50
|
|
|
51
51
|
res.sendStatus(200)
|
|
52
52
|
})
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
fastify.listen(0, (err, address) => {
|
|
55
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
56
56
|
t.error(err)
|
|
57
57
|
sget({
|
|
58
58
|
method: 'GET',
|
package/test/form-data.test.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('tap')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
|
-
const fastifyFormBody = require('fastify
|
|
5
|
+
const fastifyFormBody = require('@fastify/formbody')
|
|
6
6
|
const Express = require('express')
|
|
7
7
|
const bodyParser = require('body-parser')
|
|
8
8
|
const sget = require('simple-get').concat
|
|
@@ -22,7 +22,7 @@ test('POST request without form body works', t => {
|
|
|
22
22
|
fastify.use(express)
|
|
23
23
|
fastify.use((req, res, next) => {
|
|
24
24
|
// body-parser default value
|
|
25
|
-
t.
|
|
25
|
+
t.same(req.body, {})
|
|
26
26
|
next()
|
|
27
27
|
})
|
|
28
28
|
})
|
|
@@ -31,7 +31,7 @@ test('POST request without form body works', t => {
|
|
|
31
31
|
return { hello: 'world' }
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
fastify.listen(0, (err, address) => {
|
|
34
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
35
35
|
t.error(err)
|
|
36
36
|
sget({
|
|
37
37
|
method: 'post',
|
|
@@ -39,8 +39,8 @@ test('POST request without form body works', t => {
|
|
|
39
39
|
timeout: 100
|
|
40
40
|
}, (err, res, data) => {
|
|
41
41
|
t.error(err)
|
|
42
|
-
t.
|
|
43
|
-
t.
|
|
42
|
+
t.equal(res.statusCode, 200)
|
|
43
|
+
t.same(JSON.parse(data), { hello: 'world' })
|
|
44
44
|
})
|
|
45
45
|
})
|
|
46
46
|
})
|
|
@@ -57,7 +57,7 @@ test('POST request with form body and without body-parser works', t => {
|
|
|
57
57
|
fastify.use(express)
|
|
58
58
|
fastify.use((req, res, next) => {
|
|
59
59
|
// req.body default value
|
|
60
|
-
t.
|
|
60
|
+
t.equal(req.body, undefined)
|
|
61
61
|
next()
|
|
62
62
|
})
|
|
63
63
|
})
|
|
@@ -66,7 +66,7 @@ test('POST request with form body and without body-parser works', t => {
|
|
|
66
66
|
return { hello: 'world' }
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
-
fastify.listen(0, (err, address) => {
|
|
69
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
70
70
|
t.error(err)
|
|
71
71
|
sget({
|
|
72
72
|
method: 'post',
|
|
@@ -75,8 +75,8 @@ test('POST request with form body and without body-parser works', t => {
|
|
|
75
75
|
timeout: 100
|
|
76
76
|
}, (err, res, data) => {
|
|
77
77
|
t.error(err)
|
|
78
|
-
t.
|
|
79
|
-
t.
|
|
78
|
+
t.equal(res.statusCode, 200)
|
|
79
|
+
t.same(JSON.parse(data), { hello: 'world' })
|
|
80
80
|
})
|
|
81
81
|
})
|
|
82
82
|
})
|
|
@@ -94,7 +94,7 @@ test('POST request with form body and body-parser hangs up', t => {
|
|
|
94
94
|
fastify.use(express)
|
|
95
95
|
fastify.use((req, res, next) => {
|
|
96
96
|
// body-parser result
|
|
97
|
-
t.
|
|
97
|
+
t.same(req.body, { input: 'test' })
|
|
98
98
|
next()
|
|
99
99
|
})
|
|
100
100
|
})
|
|
@@ -103,7 +103,7 @@ test('POST request with form body and body-parser hangs up', t => {
|
|
|
103
103
|
return { hello: 'world' }
|
|
104
104
|
})
|
|
105
105
|
|
|
106
|
-
fastify.listen(0, (err, address) => {
|
|
106
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
107
107
|
t.error(err)
|
|
108
108
|
sget({
|
|
109
109
|
method: 'post',
|
|
@@ -111,7 +111,7 @@ test('POST request with form body and body-parser hangs up', t => {
|
|
|
111
111
|
form: { input: 'test' },
|
|
112
112
|
timeout: 100
|
|
113
113
|
}, (err, res, data) => {
|
|
114
|
-
t.
|
|
114
|
+
t.equal(err.message, 'Request timed out')
|
|
115
115
|
})
|
|
116
116
|
})
|
|
117
117
|
})
|
|
@@ -128,7 +128,7 @@ test('POST request with form body and body-parser hangs up, compatibility case',
|
|
|
128
128
|
fastify.use(express)
|
|
129
129
|
fastify.use((req, res, next) => {
|
|
130
130
|
// fastify-formbody with backward compatibility result
|
|
131
|
-
t.
|
|
131
|
+
t.same(req.body, { input: 'test' })
|
|
132
132
|
next()
|
|
133
133
|
})
|
|
134
134
|
})
|
|
@@ -137,7 +137,7 @@ test('POST request with form body and body-parser hangs up, compatibility case',
|
|
|
137
137
|
return { hello: 'world' }
|
|
138
138
|
})
|
|
139
139
|
|
|
140
|
-
fastify.listen(0, (err, address) => {
|
|
140
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
141
141
|
t.error(err)
|
|
142
142
|
sget({
|
|
143
143
|
method: 'post',
|
|
@@ -146,8 +146,8 @@ test('POST request with form body and body-parser hangs up, compatibility case',
|
|
|
146
146
|
timeout: 100
|
|
147
147
|
}, (err, res, data) => {
|
|
148
148
|
t.error(err)
|
|
149
|
-
t.
|
|
150
|
-
t.
|
|
149
|
+
t.equal(res.statusCode, 200)
|
|
150
|
+
t.same(JSON.parse(data), { hello: 'world' })
|
|
151
151
|
})
|
|
152
152
|
})
|
|
153
153
|
})
|
package/test/hooks.test.js
CHANGED
|
@@ -18,8 +18,8 @@ test('onSend hook should receive valid request and reply objects if middleware f
|
|
|
18
18
|
fastify.decorateReply('testDecorator', 'testDecoratorVal')
|
|
19
19
|
|
|
20
20
|
fastify.addHook('onSend', function (request, reply, payload, next) {
|
|
21
|
-
t.
|
|
22
|
-
t.
|
|
21
|
+
t.equal(request.testDecorator, 'testDecoratorVal')
|
|
22
|
+
t.equal(reply.testDecorator, 'testDecoratorVal')
|
|
23
23
|
next()
|
|
24
24
|
})
|
|
25
25
|
|
|
@@ -32,6 +32,6 @@ test('onSend hook should receive valid request and reply objects if middleware f
|
|
|
32
32
|
url: '/'
|
|
33
33
|
}, (err, res) => {
|
|
34
34
|
t.error(err)
|
|
35
|
-
t.
|
|
35
|
+
t.equal(res.statusCode, 500)
|
|
36
36
|
})
|
|
37
37
|
})
|
package/test/middleware.test.js
CHANGED
|
@@ -30,19 +30,19 @@ test('use a middleware', t => {
|
|
|
30
30
|
reply.send({ hello: 'world' })
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
-
instance.listen(0, err => {
|
|
33
|
+
instance.listen({ port: 0 }, err => {
|
|
34
34
|
t.error(err)
|
|
35
35
|
|
|
36
|
-
t.
|
|
36
|
+
t.teardown(instance.server.close.bind(instance.server))
|
|
37
37
|
|
|
38
38
|
sget({
|
|
39
39
|
method: 'GET',
|
|
40
40
|
url: 'http://localhost:' + instance.server.address().port
|
|
41
41
|
}, (err, response, body) => {
|
|
42
42
|
t.error(err)
|
|
43
|
-
t.
|
|
44
|
-
t.
|
|
45
|
-
t.
|
|
43
|
+
t.equal(response.statusCode, 200)
|
|
44
|
+
t.equal(response.headers['content-length'], '' + body.length)
|
|
45
|
+
t.same(JSON.parse(body), { hello: 'world' })
|
|
46
46
|
})
|
|
47
47
|
})
|
|
48
48
|
})
|
|
@@ -60,10 +60,10 @@ test('use cors', t => {
|
|
|
60
60
|
reply.send({ hello: 'world' })
|
|
61
61
|
})
|
|
62
62
|
|
|
63
|
-
instance.listen(0, err => {
|
|
63
|
+
instance.listen({ port: 0 }, err => {
|
|
64
64
|
t.error(err)
|
|
65
65
|
|
|
66
|
-
t.
|
|
66
|
+
t.teardown(instance.server.close.bind(instance.server))
|
|
67
67
|
|
|
68
68
|
sget({
|
|
69
69
|
method: 'GET',
|
|
@@ -88,10 +88,10 @@ test('use helmet', t => {
|
|
|
88
88
|
reply.send({ hello: 'world' })
|
|
89
89
|
})
|
|
90
90
|
|
|
91
|
-
instance.listen(0, err => {
|
|
91
|
+
instance.listen({ port: 0 }, err => {
|
|
92
92
|
t.error(err)
|
|
93
93
|
|
|
94
|
-
t.
|
|
94
|
+
t.teardown(instance.server.close.bind(instance.server))
|
|
95
95
|
|
|
96
96
|
sget({
|
|
97
97
|
method: 'GET',
|
|
@@ -117,10 +117,10 @@ test('use helmet and cors', t => {
|
|
|
117
117
|
reply.send({ hello: 'world' })
|
|
118
118
|
})
|
|
119
119
|
|
|
120
|
-
instance.listen(0, err => {
|
|
120
|
+
instance.listen({ port: 0 }, err => {
|
|
121
121
|
t.error(err)
|
|
122
122
|
|
|
123
|
-
t.
|
|
123
|
+
t.teardown(instance.server.close.bind(instance.server))
|
|
124
124
|
|
|
125
125
|
sget({
|
|
126
126
|
method: 'GET',
|
|
@@ -176,9 +176,9 @@ test('middlewares with prefix', t => {
|
|
|
176
176
|
instance.get('/prefix/', handler)
|
|
177
177
|
instance.get('/prefix/inner', handler)
|
|
178
178
|
|
|
179
|
-
instance.listen(0, err => {
|
|
179
|
+
instance.listen({ port: 0 }, err => {
|
|
180
180
|
t.error(err)
|
|
181
|
-
t.
|
|
181
|
+
t.teardown(instance.server.close.bind(instance.server))
|
|
182
182
|
|
|
183
183
|
t.test('/', t => {
|
|
184
184
|
t.plan(2)
|
|
@@ -188,7 +188,7 @@ test('middlewares with prefix', t => {
|
|
|
188
188
|
json: true
|
|
189
189
|
}, (err, response, body) => {
|
|
190
190
|
t.error(err)
|
|
191
|
-
t.
|
|
191
|
+
t.same(body, {
|
|
192
192
|
global: true,
|
|
193
193
|
global2: true,
|
|
194
194
|
root: true
|
|
@@ -204,7 +204,7 @@ test('middlewares with prefix', t => {
|
|
|
204
204
|
json: true
|
|
205
205
|
}, (err, response, body) => {
|
|
206
206
|
t.error(err)
|
|
207
|
-
t.
|
|
207
|
+
t.same(body, {
|
|
208
208
|
prefixed: true,
|
|
209
209
|
global: true,
|
|
210
210
|
global2: true,
|
|
@@ -222,7 +222,7 @@ test('middlewares with prefix', t => {
|
|
|
222
222
|
json: true
|
|
223
223
|
}, (err, response, body) => {
|
|
224
224
|
t.error(err)
|
|
225
|
-
t.
|
|
225
|
+
t.same(body, {
|
|
226
226
|
prefixed: true,
|
|
227
227
|
slashed: true,
|
|
228
228
|
global: true,
|
|
@@ -240,7 +240,7 @@ test('middlewares with prefix', t => {
|
|
|
240
240
|
json: true
|
|
241
241
|
}, (err, response, body) => {
|
|
242
242
|
t.error(err)
|
|
243
|
-
t.
|
|
243
|
+
t.same(body, {
|
|
244
244
|
prefixed: true,
|
|
245
245
|
slashed: true,
|
|
246
246
|
global: true,
|
|
@@ -290,15 +290,15 @@ test('res.end should block middleware execution', t => {
|
|
|
290
290
|
t.fail('we should no be here')
|
|
291
291
|
})
|
|
292
292
|
|
|
293
|
-
instance.listen(0, (err, address) => {
|
|
293
|
+
instance.listen({ port: 0 }, (err, address) => {
|
|
294
294
|
t.error(err)
|
|
295
295
|
sget({
|
|
296
296
|
method: 'GET',
|
|
297
297
|
url: address
|
|
298
298
|
}, (err, res, data) => {
|
|
299
299
|
t.error(err)
|
|
300
|
-
t.
|
|
301
|
-
t.
|
|
300
|
+
t.equal(res.statusCode, 200)
|
|
301
|
+
t.equal(data.toString(), 'hello')
|
|
302
302
|
})
|
|
303
303
|
})
|
|
304
304
|
})
|
|
@@ -331,15 +331,15 @@ test('Use a middleware inside a plugin after an encapsulated plugin', t => {
|
|
|
331
331
|
next()
|
|
332
332
|
}))
|
|
333
333
|
|
|
334
|
-
f.listen(0, (err, address) => {
|
|
334
|
+
f.listen({ port: 0 }, (err, address) => {
|
|
335
335
|
t.error(err)
|
|
336
336
|
sget({
|
|
337
337
|
method: 'GET',
|
|
338
338
|
url: address
|
|
339
339
|
}, (err, res, data) => {
|
|
340
340
|
t.error(err)
|
|
341
|
-
t.
|
|
342
|
-
t.
|
|
341
|
+
t.equal(res.statusCode, 200)
|
|
342
|
+
t.same(JSON.parse(data), { hello: 'world' })
|
|
343
343
|
})
|
|
344
344
|
})
|
|
345
345
|
})
|
|
@@ -352,14 +352,14 @@ test('middlewares should run in the order in which they are defined', t => {
|
|
|
352
352
|
|
|
353
353
|
f.register(fp(function (instance, opts, next) {
|
|
354
354
|
instance.use(function (req, res, next) {
|
|
355
|
-
t.
|
|
355
|
+
t.equal(req.previous, undefined)
|
|
356
356
|
req.previous = 1
|
|
357
357
|
next()
|
|
358
358
|
})
|
|
359
359
|
|
|
360
360
|
instance.register(fp(function (i, opts, next) {
|
|
361
361
|
i.use(function (req, res, next) {
|
|
362
|
-
t.
|
|
362
|
+
t.equal(req.previous, 2)
|
|
363
363
|
req.previous = 3
|
|
364
364
|
next()
|
|
365
365
|
})
|
|
@@ -367,7 +367,7 @@ test('middlewares should run in the order in which they are defined', t => {
|
|
|
367
367
|
}))
|
|
368
368
|
|
|
369
369
|
instance.use(function (req, res, next) {
|
|
370
|
-
t.
|
|
370
|
+
t.equal(req.previous, 1)
|
|
371
371
|
req.previous = 2
|
|
372
372
|
next()
|
|
373
373
|
})
|
|
@@ -377,19 +377,19 @@ test('middlewares should run in the order in which they are defined', t => {
|
|
|
377
377
|
|
|
378
378
|
f.register(function (instance, opts, next) {
|
|
379
379
|
instance.use(function (req, res, next) {
|
|
380
|
-
t.
|
|
380
|
+
t.equal(req.previous, 3)
|
|
381
381
|
req.previous = 4
|
|
382
382
|
next()
|
|
383
383
|
})
|
|
384
384
|
|
|
385
385
|
instance.get('/', function (request, reply) {
|
|
386
|
-
t.
|
|
386
|
+
t.equal(request.raw.previous, 5)
|
|
387
387
|
reply.send({ hello: 'world' })
|
|
388
388
|
})
|
|
389
389
|
|
|
390
390
|
instance.register(fp(function (i, opts, next) {
|
|
391
391
|
i.use(function (req, res, next) {
|
|
392
|
-
t.
|
|
392
|
+
t.equal(req.previous, 4)
|
|
393
393
|
req.previous = 5
|
|
394
394
|
next()
|
|
395
395
|
})
|
|
@@ -399,15 +399,15 @@ test('middlewares should run in the order in which they are defined', t => {
|
|
|
399
399
|
next()
|
|
400
400
|
})
|
|
401
401
|
|
|
402
|
-
f.listen(0, (err, address) => {
|
|
402
|
+
f.listen({ port: 0 }, (err, address) => {
|
|
403
403
|
t.error(err)
|
|
404
404
|
sget({
|
|
405
405
|
method: 'GET',
|
|
406
406
|
url: address
|
|
407
407
|
}, (err, res, data) => {
|
|
408
408
|
t.error(err)
|
|
409
|
-
t.
|
|
410
|
-
t.
|
|
409
|
+
t.equal(res.statusCode, 200)
|
|
410
|
+
t.same(JSON.parse(data), { hello: 'world' })
|
|
411
411
|
})
|
|
412
412
|
})
|
|
413
413
|
})
|