@fastify/express 4.0.1 → 4.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/ci.yml +1 -1
- package/README.md +25 -12
- package/eslint.config.js +6 -0
- package/package.json +36 -5
- package/test/404s.test.js +44 -44
- package/test/application.test.js +9 -9
- package/test/basic.test.js +71 -71
- package/test/enhance-request.test.js +5 -5
- package/test/form-data.test.js +9 -9
- package/test/hooks.test.js +4 -4
- package/test/middleware.test.js +38 -38
- package/types/index.d.ts +2 -2
- package/types/index.test-d.ts +3 -3
package/test/basic.test.js
CHANGED
|
@@ -18,7 +18,7 @@ test('Should support connect style middlewares', t => {
|
|
|
18
18
|
.register(expressPlugin)
|
|
19
19
|
.after(() => { fastify.use(cors()) })
|
|
20
20
|
|
|
21
|
-
fastify.get('/', async (
|
|
21
|
+
fastify.get('/', async () => {
|
|
22
22
|
return { hello: 'world' }
|
|
23
23
|
})
|
|
24
24
|
|
|
@@ -45,12 +45,12 @@ test('Should support connect style middlewares (async await)', async t => {
|
|
|
45
45
|
await fastify.register(expressPlugin)
|
|
46
46
|
fastify.use(cors())
|
|
47
47
|
|
|
48
|
-
fastify.get('/', async (
|
|
48
|
+
fastify.get('/', async () => {
|
|
49
49
|
return { hello: 'world' }
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
const address = await fastify.listen({ port: 0 })
|
|
53
|
-
return new Promise((resolve
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
54
|
sget({
|
|
55
55
|
method: 'GET',
|
|
56
56
|
url: address
|
|
@@ -74,12 +74,12 @@ test('Should support connect style middlewares (async await after)', async t =>
|
|
|
74
74
|
await fastify.after()
|
|
75
75
|
fastify.use(cors())
|
|
76
76
|
|
|
77
|
-
fastify.get('/', async (
|
|
77
|
+
fastify.get('/', async () => {
|
|
78
78
|
return { hello: 'world' }
|
|
79
79
|
})
|
|
80
80
|
|
|
81
81
|
const address = await fastify.listen({ port: 0 })
|
|
82
|
-
return new Promise((resolve
|
|
82
|
+
return new Promise((resolve) => {
|
|
83
83
|
sget({
|
|
84
84
|
method: 'GET',
|
|
85
85
|
url: address
|
|
@@ -103,11 +103,11 @@ test('Should support per path middlewares', t => {
|
|
|
103
103
|
.register(expressPlugin)
|
|
104
104
|
.after(() => { fastify.use('/cors', cors()) })
|
|
105
105
|
|
|
106
|
-
fastify.get('/cors/hello', async (
|
|
106
|
+
fastify.get('/cors/hello', async () => {
|
|
107
107
|
return { hello: 'world' }
|
|
108
108
|
})
|
|
109
109
|
|
|
110
|
-
fastify.get('/', async (
|
|
110
|
+
fastify.get('/', async () => {
|
|
111
111
|
return { hello: 'world' }
|
|
112
112
|
})
|
|
113
113
|
|
|
@@ -116,7 +116,7 @@ test('Should support per path middlewares', t => {
|
|
|
116
116
|
sget({
|
|
117
117
|
method: 'GET',
|
|
118
118
|
url: address + '/cors/hello'
|
|
119
|
-
}, (err, res
|
|
119
|
+
}, (err, res) => {
|
|
120
120
|
t.error(err)
|
|
121
121
|
t.match(res.headers, {
|
|
122
122
|
'access-control-allow-origin': '*'
|
|
@@ -126,7 +126,7 @@ test('Should support per path middlewares', t => {
|
|
|
126
126
|
sget({
|
|
127
127
|
method: 'GET',
|
|
128
128
|
url: address
|
|
129
|
-
}, (err, res
|
|
129
|
+
}, (err, res) => {
|
|
130
130
|
t.error(err)
|
|
131
131
|
t.notOk(res.headers['access-control-allow-origin'])
|
|
132
132
|
})
|
|
@@ -159,7 +159,7 @@ test('Should support complex middlewares', t => {
|
|
|
159
159
|
headers: {
|
|
160
160
|
authorization: 'Bearer 123456789'
|
|
161
161
|
}
|
|
162
|
-
}, (err
|
|
162
|
+
}, (err) => {
|
|
163
163
|
t.error(err)
|
|
164
164
|
fastify.close()
|
|
165
165
|
})
|
|
@@ -171,18 +171,18 @@ test('Encapsulation support / 1', t => {
|
|
|
171
171
|
|
|
172
172
|
const fastify = Fastify()
|
|
173
173
|
|
|
174
|
-
fastify.register((instance,
|
|
174
|
+
fastify.register((instance, _opts, next) => {
|
|
175
175
|
instance.register(expressPlugin)
|
|
176
176
|
.after(() => { instance.use(middleware) })
|
|
177
177
|
|
|
178
|
-
instance.get('/plugin', (
|
|
178
|
+
instance.get('/plugin', (_req, reply) => {
|
|
179
179
|
reply.send('ok')
|
|
180
180
|
})
|
|
181
181
|
|
|
182
182
|
next()
|
|
183
183
|
})
|
|
184
184
|
|
|
185
|
-
fastify.get('/', (
|
|
185
|
+
fastify.get('/', (_req, reply) => {
|
|
186
186
|
reply.send('ok')
|
|
187
187
|
})
|
|
188
188
|
|
|
@@ -191,13 +191,13 @@ test('Encapsulation support / 1', t => {
|
|
|
191
191
|
sget({
|
|
192
192
|
method: 'GET',
|
|
193
193
|
url: address
|
|
194
|
-
}, (err
|
|
194
|
+
}, (err) => {
|
|
195
195
|
t.error(err)
|
|
196
196
|
fastify.close()
|
|
197
197
|
})
|
|
198
198
|
})
|
|
199
199
|
|
|
200
|
-
function middleware (
|
|
200
|
+
function middleware () {
|
|
201
201
|
t.fail('Shuld not be called')
|
|
202
202
|
}
|
|
203
203
|
})
|
|
@@ -209,16 +209,16 @@ test('Encapsulation support / 2', t => {
|
|
|
209
209
|
|
|
210
210
|
fastify.register(expressPlugin)
|
|
211
211
|
|
|
212
|
-
fastify.register((instance,
|
|
212
|
+
fastify.register((instance, _opts, next) => {
|
|
213
213
|
instance.use(middleware)
|
|
214
|
-
instance.get('/plugin', (
|
|
214
|
+
instance.get('/plugin', (_req, reply) => {
|
|
215
215
|
reply.send('ok')
|
|
216
216
|
})
|
|
217
217
|
|
|
218
218
|
next()
|
|
219
219
|
})
|
|
220
220
|
|
|
221
|
-
fastify.get('/', (
|
|
221
|
+
fastify.get('/', (_req, reply) => {
|
|
222
222
|
reply.send('ok')
|
|
223
223
|
})
|
|
224
224
|
|
|
@@ -227,13 +227,13 @@ test('Encapsulation support / 2', t => {
|
|
|
227
227
|
sget({
|
|
228
228
|
method: 'GET',
|
|
229
229
|
url: address
|
|
230
|
-
}, (err
|
|
230
|
+
}, (err) => {
|
|
231
231
|
t.error(err)
|
|
232
232
|
fastify.close()
|
|
233
233
|
})
|
|
234
234
|
})
|
|
235
235
|
|
|
236
|
-
function middleware (
|
|
236
|
+
function middleware () {
|
|
237
237
|
t.fail('Shuld not be called')
|
|
238
238
|
}
|
|
239
239
|
})
|
|
@@ -247,16 +247,16 @@ test('Encapsulation support / 3', t => {
|
|
|
247
247
|
|
|
248
248
|
fastify.register(expressPlugin)
|
|
249
249
|
|
|
250
|
-
fastify.register((instance,
|
|
250
|
+
fastify.register((instance, _opts, next) => {
|
|
251
251
|
instance.use(cors())
|
|
252
|
-
instance.get('/plugin', (
|
|
252
|
+
instance.get('/plugin', (_req, reply) => {
|
|
253
253
|
reply.send('ok')
|
|
254
254
|
})
|
|
255
255
|
|
|
256
256
|
next()
|
|
257
257
|
})
|
|
258
258
|
|
|
259
|
-
fastify.get('/', (
|
|
259
|
+
fastify.get('/', (_req, reply) => {
|
|
260
260
|
reply.send('ok')
|
|
261
261
|
})
|
|
262
262
|
|
|
@@ -265,7 +265,7 @@ test('Encapsulation support / 3', t => {
|
|
|
265
265
|
sget({
|
|
266
266
|
method: 'GET',
|
|
267
267
|
url: address + '/plugin'
|
|
268
|
-
}, (err, res
|
|
268
|
+
}, (err, res) => {
|
|
269
269
|
t.error(err)
|
|
270
270
|
t.match(res.headers, {
|
|
271
271
|
'access-control-allow-origin': '*'
|
|
@@ -275,7 +275,7 @@ test('Encapsulation support / 3', t => {
|
|
|
275
275
|
sget({
|
|
276
276
|
method: 'GET',
|
|
277
277
|
url: address
|
|
278
|
-
}, (err, res
|
|
278
|
+
}, (err, res) => {
|
|
279
279
|
t.error(err)
|
|
280
280
|
t.notMatch(res.headers, {
|
|
281
281
|
'access-control-allow-origin': '*'
|
|
@@ -296,16 +296,16 @@ test('Encapsulation support / 4', t => {
|
|
|
296
296
|
fastify.use(middleware1)
|
|
297
297
|
})
|
|
298
298
|
|
|
299
|
-
fastify.register((instance,
|
|
299
|
+
fastify.register((instance, _opts, next) => {
|
|
300
300
|
instance.use(middleware2)
|
|
301
|
-
instance.get('/plugin', (
|
|
301
|
+
instance.get('/plugin', (_req, reply) => {
|
|
302
302
|
reply.send('ok')
|
|
303
303
|
})
|
|
304
304
|
|
|
305
305
|
next()
|
|
306
306
|
})
|
|
307
307
|
|
|
308
|
-
fastify.get('/', (
|
|
308
|
+
fastify.get('/', (_req, reply) => {
|
|
309
309
|
reply.send('ok')
|
|
310
310
|
})
|
|
311
311
|
|
|
@@ -314,7 +314,7 @@ test('Encapsulation support / 4', t => {
|
|
|
314
314
|
sget({
|
|
315
315
|
method: 'GET',
|
|
316
316
|
url: address + '/plugin'
|
|
317
|
-
}, (err, res
|
|
317
|
+
}, (err, res) => {
|
|
318
318
|
t.error(err)
|
|
319
319
|
t.match(res.headers, {
|
|
320
320
|
'x-middleware-1': 'true',
|
|
@@ -325,7 +325,7 @@ test('Encapsulation support / 4', t => {
|
|
|
325
325
|
sget({
|
|
326
326
|
method: 'GET',
|
|
327
327
|
url: address
|
|
328
|
-
}, (err, res
|
|
328
|
+
}, (err, res) => {
|
|
329
329
|
t.error(err)
|
|
330
330
|
t.match(res.headers, {
|
|
331
331
|
'x-middleware-1': 'true'
|
|
@@ -333,12 +333,12 @@ test('Encapsulation support / 4', t => {
|
|
|
333
333
|
})
|
|
334
334
|
})
|
|
335
335
|
|
|
336
|
-
function middleware1 (
|
|
336
|
+
function middleware1 (_req, res, next) {
|
|
337
337
|
res.setHeader('x-middleware-1', true)
|
|
338
338
|
next()
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
-
function middleware2 (
|
|
341
|
+
function middleware2 (_req, res, next) {
|
|
342
342
|
res.setHeader('x-middleware-2', true)
|
|
343
343
|
next()
|
|
344
344
|
}
|
|
@@ -356,15 +356,15 @@ test('Encapsulation support / 5', t => {
|
|
|
356
356
|
fastify.use(middleware1)
|
|
357
357
|
})
|
|
358
358
|
|
|
359
|
-
fastify.register((instance,
|
|
359
|
+
fastify.register((instance, _opts, next) => {
|
|
360
360
|
instance.use(middleware2)
|
|
361
|
-
instance.get('/', (
|
|
361
|
+
instance.get('/', (_req, reply) => {
|
|
362
362
|
reply.send('ok')
|
|
363
363
|
})
|
|
364
364
|
|
|
365
|
-
instance.register((i,
|
|
365
|
+
instance.register((i, _opts, next) => {
|
|
366
366
|
i.use(middleware3)
|
|
367
|
-
i.get('/nested', (
|
|
367
|
+
i.get('/nested', (_req, reply) => {
|
|
368
368
|
reply.send('ok')
|
|
369
369
|
})
|
|
370
370
|
|
|
@@ -374,7 +374,7 @@ test('Encapsulation support / 5', t => {
|
|
|
374
374
|
next()
|
|
375
375
|
}, { prefix: '/plugin' })
|
|
376
376
|
|
|
377
|
-
fastify.get('/', (
|
|
377
|
+
fastify.get('/', (_req, reply) => {
|
|
378
378
|
reply.send('ok')
|
|
379
379
|
})
|
|
380
380
|
|
|
@@ -383,7 +383,7 @@ test('Encapsulation support / 5', t => {
|
|
|
383
383
|
sget({
|
|
384
384
|
method: 'GET',
|
|
385
385
|
url: address + '/plugin/nested'
|
|
386
|
-
}, (err, res
|
|
386
|
+
}, (err, res) => {
|
|
387
387
|
t.error(err)
|
|
388
388
|
t.match(res.headers, {
|
|
389
389
|
'x-middleware-1': 'true',
|
|
@@ -395,7 +395,7 @@ test('Encapsulation support / 5', t => {
|
|
|
395
395
|
sget({
|
|
396
396
|
method: 'GET',
|
|
397
397
|
url: address + '/plugin'
|
|
398
|
-
}, (err, res
|
|
398
|
+
}, (err, res) => {
|
|
399
399
|
t.error(err)
|
|
400
400
|
t.match(res.headers, {
|
|
401
401
|
'x-middleware-1': 'true',
|
|
@@ -406,7 +406,7 @@ test('Encapsulation support / 5', t => {
|
|
|
406
406
|
sget({
|
|
407
407
|
method: 'GET',
|
|
408
408
|
url: address
|
|
409
|
-
}, (err, res
|
|
409
|
+
}, (err, res) => {
|
|
410
410
|
t.error(err)
|
|
411
411
|
t.match(res.headers, {
|
|
412
412
|
'x-middleware-1': 'true'
|
|
@@ -414,17 +414,17 @@ test('Encapsulation support / 5', t => {
|
|
|
414
414
|
})
|
|
415
415
|
})
|
|
416
416
|
|
|
417
|
-
function middleware1 (
|
|
417
|
+
function middleware1 (_req, res, next) {
|
|
418
418
|
res.setHeader('x-middleware-1', true)
|
|
419
419
|
next()
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
function middleware2 (
|
|
422
|
+
function middleware2 (_req, res, next) {
|
|
423
423
|
res.setHeader('x-middleware-2', true)
|
|
424
424
|
next()
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
-
function middleware3 (
|
|
427
|
+
function middleware3 (_req, res, next) {
|
|
428
428
|
res.setHeader('x-middleware-3', true)
|
|
429
429
|
next()
|
|
430
430
|
}
|
|
@@ -445,7 +445,7 @@ test('Middleware chain', t => {
|
|
|
445
445
|
.use(middleware3)
|
|
446
446
|
})
|
|
447
447
|
|
|
448
|
-
fastify.get('/', async (
|
|
448
|
+
fastify.get('/', async () => {
|
|
449
449
|
return { hello: 'world' }
|
|
450
450
|
})
|
|
451
451
|
|
|
@@ -454,23 +454,23 @@ test('Middleware chain', t => {
|
|
|
454
454
|
sget({
|
|
455
455
|
method: 'GET',
|
|
456
456
|
url: address
|
|
457
|
-
}, (err
|
|
457
|
+
}, (err) => {
|
|
458
458
|
t.error(err)
|
|
459
459
|
fastify.close()
|
|
460
460
|
})
|
|
461
461
|
})
|
|
462
462
|
|
|
463
|
-
function middleware1 (
|
|
463
|
+
function middleware1 (_req, _res, next) {
|
|
464
464
|
t.equal(order.shift(), 1)
|
|
465
465
|
next()
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
-
function middleware2 (
|
|
468
|
+
function middleware2 (_req, _res, next) {
|
|
469
469
|
t.equal(order.shift(), 2)
|
|
470
470
|
next()
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
-
function middleware3 (
|
|
473
|
+
function middleware3 (_req, _res, next) {
|
|
474
474
|
t.equal(order.shift(), 3)
|
|
475
475
|
next()
|
|
476
476
|
}
|
|
@@ -491,7 +491,7 @@ test('Middleware chain (with errors) / 1', t => {
|
|
|
491
491
|
.use(middleware3)
|
|
492
492
|
})
|
|
493
493
|
|
|
494
|
-
fastify.get('/', async (
|
|
494
|
+
fastify.get('/', async () => {
|
|
495
495
|
return { hello: 'world' }
|
|
496
496
|
})
|
|
497
497
|
|
|
@@ -500,25 +500,25 @@ test('Middleware chain (with errors) / 1', t => {
|
|
|
500
500
|
sget({
|
|
501
501
|
method: 'GET',
|
|
502
502
|
url: address
|
|
503
|
-
}, (err, res
|
|
503
|
+
}, (err, res) => {
|
|
504
504
|
t.error(err)
|
|
505
505
|
t.equal(res.statusCode, 500)
|
|
506
506
|
fastify.close()
|
|
507
507
|
})
|
|
508
508
|
})
|
|
509
509
|
|
|
510
|
-
function middleware1 (
|
|
510
|
+
function middleware1 (_req, _res, next) {
|
|
511
511
|
t.equal(order.shift(), 1)
|
|
512
512
|
next(new Error('middleware1'))
|
|
513
513
|
}
|
|
514
514
|
|
|
515
|
-
function middleware2 (err,
|
|
515
|
+
function middleware2 (err, _req, _res, next) {
|
|
516
516
|
t.equal(err.message, 'middleware1')
|
|
517
517
|
t.equal(order.shift(), 2)
|
|
518
518
|
next(new Error('middleware2'))
|
|
519
519
|
}
|
|
520
520
|
|
|
521
|
-
function middleware3 (err,
|
|
521
|
+
function middleware3 (err, _req, _res, next) {
|
|
522
522
|
t.equal(err.message, 'middleware2')
|
|
523
523
|
t.equal(order.shift(), 3)
|
|
524
524
|
next(new Error('kaboom'))
|
|
@@ -531,7 +531,7 @@ test('Middleware chain (with errors) / 2', t => {
|
|
|
531
531
|
const order = [1, 2]
|
|
532
532
|
const fastify = Fastify()
|
|
533
533
|
|
|
534
|
-
fastify.setErrorHandler((err,
|
|
534
|
+
fastify.setErrorHandler((err, _req, reply) => {
|
|
535
535
|
t.equal(err.message, 'middleware2')
|
|
536
536
|
reply.send(err)
|
|
537
537
|
})
|
|
@@ -545,7 +545,7 @@ test('Middleware chain (with errors) / 2', t => {
|
|
|
545
545
|
.use(middleware3)
|
|
546
546
|
})
|
|
547
547
|
|
|
548
|
-
fastify.get('/', async (
|
|
548
|
+
fastify.get('/', async () => {
|
|
549
549
|
return { hello: 'world' }
|
|
550
550
|
})
|
|
551
551
|
|
|
@@ -554,25 +554,25 @@ test('Middleware chain (with errors) / 2', t => {
|
|
|
554
554
|
sget({
|
|
555
555
|
method: 'GET',
|
|
556
556
|
url: address
|
|
557
|
-
}, (err, res
|
|
557
|
+
}, (err, res) => {
|
|
558
558
|
t.error(err)
|
|
559
559
|
t.equal(res.statusCode, 500)
|
|
560
560
|
fastify.close()
|
|
561
561
|
})
|
|
562
562
|
})
|
|
563
563
|
|
|
564
|
-
function middleware1 (
|
|
564
|
+
function middleware1 (_req, _res, next) {
|
|
565
565
|
t.equal(order.shift(), 1)
|
|
566
566
|
next(new Error('middleware1'))
|
|
567
567
|
}
|
|
568
568
|
|
|
569
|
-
function middleware2 (err,
|
|
569
|
+
function middleware2 (err, _req, _res, next) {
|
|
570
570
|
t.equal(err.message, 'middleware1')
|
|
571
571
|
t.equal(order.shift(), 2)
|
|
572
572
|
next(new Error('middleware2'))
|
|
573
573
|
}
|
|
574
574
|
|
|
575
|
-
function middleware3 (
|
|
575
|
+
function middleware3 () {
|
|
576
576
|
t.fail('We should not be here')
|
|
577
577
|
}
|
|
578
578
|
})
|
|
@@ -590,29 +590,29 @@ test('Send a response from a middleware', t => {
|
|
|
590
590
|
.use(middleware2)
|
|
591
591
|
})
|
|
592
592
|
|
|
593
|
-
fastify.addHook('preValidation', (
|
|
593
|
+
fastify.addHook('preValidation', () => {
|
|
594
594
|
t.fail('We should not be here')
|
|
595
595
|
})
|
|
596
596
|
|
|
597
|
-
fastify.addHook('preParsing', (
|
|
597
|
+
fastify.addHook('preParsing', () => {
|
|
598
598
|
t.fail('We should not be here')
|
|
599
599
|
})
|
|
600
600
|
|
|
601
|
-
fastify.addHook('preHandler', (
|
|
601
|
+
fastify.addHook('preHandler', () => {
|
|
602
602
|
t.fail('We should not be here')
|
|
603
603
|
})
|
|
604
604
|
|
|
605
|
-
fastify.addHook('onSend', (
|
|
605
|
+
fastify.addHook('onSend', (_req, _reply, payload, next) => {
|
|
606
606
|
t.ok('called')
|
|
607
607
|
next(null, payload)
|
|
608
608
|
})
|
|
609
609
|
|
|
610
|
-
fastify.addHook('onResponse', (
|
|
610
|
+
fastify.addHook('onResponse', (_req, _reply, next) => {
|
|
611
611
|
t.ok('called')
|
|
612
612
|
next()
|
|
613
613
|
})
|
|
614
614
|
|
|
615
|
-
fastify.get('/', (
|
|
615
|
+
fastify.get('/', () => {
|
|
616
616
|
t.fail('We should not be here')
|
|
617
617
|
})
|
|
618
618
|
|
|
@@ -622,18 +622,18 @@ test('Send a response from a middleware', t => {
|
|
|
622
622
|
method: 'GET',
|
|
623
623
|
url: address,
|
|
624
624
|
json: true
|
|
625
|
-
}, (err,
|
|
625
|
+
}, (err, _res, data) => {
|
|
626
626
|
t.error(err)
|
|
627
627
|
t.same(data, { hello: 'world' })
|
|
628
628
|
fastify.close()
|
|
629
629
|
})
|
|
630
630
|
})
|
|
631
631
|
|
|
632
|
-
function middleware1 (
|
|
632
|
+
function middleware1 (_req, res) {
|
|
633
633
|
res.send({ hello: 'world' })
|
|
634
634
|
}
|
|
635
635
|
|
|
636
|
-
function middleware2 (
|
|
636
|
+
function middleware2 () {
|
|
637
637
|
t.fail('We should not be here')
|
|
638
638
|
}
|
|
639
639
|
})
|
|
@@ -645,13 +645,13 @@ test('Should support plugin level prefix', t => {
|
|
|
645
645
|
|
|
646
646
|
fastify.register(expressPlugin)
|
|
647
647
|
|
|
648
|
-
fastify.register((instance,
|
|
649
|
-
instance.use('/world', (
|
|
648
|
+
fastify.register((instance, _opts, next) => {
|
|
649
|
+
instance.use('/world', (_req, res, next) => {
|
|
650
650
|
res.setHeader('x-foo', 'bar')
|
|
651
651
|
next()
|
|
652
652
|
})
|
|
653
653
|
|
|
654
|
-
instance.get('/world', (
|
|
654
|
+
instance.get('/world', (_req, reply) => {
|
|
655
655
|
reply.send({ hello: 'world' })
|
|
656
656
|
})
|
|
657
657
|
|
|
@@ -30,7 +30,7 @@ test('Should enhance the Node.js core request/response objects', t => {
|
|
|
30
30
|
sget({
|
|
31
31
|
method: 'GET',
|
|
32
32
|
url: address
|
|
33
|
-
}, (err
|
|
33
|
+
}, (err) => {
|
|
34
34
|
t.error(err)
|
|
35
35
|
})
|
|
36
36
|
})
|
|
@@ -62,7 +62,7 @@ test('trust proxy protocol', (t) => {
|
|
|
62
62
|
'X-Forwarded-Proto': 'lorem'
|
|
63
63
|
},
|
|
64
64
|
url: address
|
|
65
|
-
}, (err
|
|
65
|
+
}, (err) => {
|
|
66
66
|
t.error(err)
|
|
67
67
|
})
|
|
68
68
|
})
|
|
@@ -92,14 +92,14 @@ test('passing createProxyHandler sets up a Proxy with Express req', t => {
|
|
|
92
92
|
})
|
|
93
93
|
})
|
|
94
94
|
.after(() => {
|
|
95
|
-
fastify.use(function (req,
|
|
95
|
+
fastify.use(function (req, _res, next) {
|
|
96
96
|
req.customField = testString
|
|
97
97
|
t.equal(req.customField, testString)
|
|
98
98
|
next()
|
|
99
99
|
})
|
|
100
100
|
})
|
|
101
101
|
|
|
102
|
-
fastify.get('/', function (
|
|
102
|
+
fastify.get('/', function (_request, reply) {
|
|
103
103
|
reply.send({ hello: 'world' })
|
|
104
104
|
})
|
|
105
105
|
|
|
@@ -152,7 +152,7 @@ test('createProxyHandler has access to Fastify request object', t => {
|
|
|
152
152
|
})
|
|
153
153
|
})
|
|
154
154
|
.after(() => {
|
|
155
|
-
fastify.use(function (req,
|
|
155
|
+
fastify.use(function (req, _res, next) {
|
|
156
156
|
t.equal(req.getAndSetFastify, startTestString)
|
|
157
157
|
t.equal(req.getOnlyFastify, startTestString)
|
|
158
158
|
req.getAndSetFastify = 'updated'
|
package/test/form-data.test.js
CHANGED
|
@@ -20,14 +20,14 @@ test('POST request without form body works', t => {
|
|
|
20
20
|
.after(() => {
|
|
21
21
|
express.use(bodyParser.urlencoded({ extended: false }))
|
|
22
22
|
fastify.use(express)
|
|
23
|
-
fastify.use((req,
|
|
23
|
+
fastify.use((req, _res, next) => {
|
|
24
24
|
// body-parser default value
|
|
25
25
|
t.same(req.body, {})
|
|
26
26
|
next()
|
|
27
27
|
})
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
-
fastify.post('/hello', (
|
|
30
|
+
fastify.post('/hello', () => {
|
|
31
31
|
return { hello: 'world' }
|
|
32
32
|
})
|
|
33
33
|
|
|
@@ -55,14 +55,14 @@ test('POST request with form body and without body-parser works', t => {
|
|
|
55
55
|
fastify.register(expressPlugin)
|
|
56
56
|
.after(() => {
|
|
57
57
|
fastify.use(express)
|
|
58
|
-
fastify.use((req,
|
|
58
|
+
fastify.use((req, _res, next) => {
|
|
59
59
|
// req.body default value
|
|
60
60
|
t.equal(req.body, undefined)
|
|
61
61
|
next()
|
|
62
62
|
})
|
|
63
63
|
})
|
|
64
64
|
|
|
65
|
-
fastify.post('/hello', (
|
|
65
|
+
fastify.post('/hello', () => {
|
|
66
66
|
return { hello: 'world' }
|
|
67
67
|
})
|
|
68
68
|
|
|
@@ -92,14 +92,14 @@ test('POST request with form body and body-parser hangs up', t => {
|
|
|
92
92
|
.after(() => {
|
|
93
93
|
express.use(bodyParser.urlencoded({ extended: false }))
|
|
94
94
|
fastify.use(express)
|
|
95
|
-
fastify.use((req,
|
|
95
|
+
fastify.use((req, _res, next) => {
|
|
96
96
|
// body-parser result
|
|
97
97
|
t.same(req.body, { input: 'test' })
|
|
98
98
|
next()
|
|
99
99
|
})
|
|
100
100
|
})
|
|
101
101
|
|
|
102
|
-
fastify.post('/hello', (
|
|
102
|
+
fastify.post('/hello', () => {
|
|
103
103
|
return { hello: 'world' }
|
|
104
104
|
})
|
|
105
105
|
|
|
@@ -110,7 +110,7 @@ test('POST request with form body and body-parser hangs up', t => {
|
|
|
110
110
|
url: address + '/hello',
|
|
111
111
|
form: { input: 'test' },
|
|
112
112
|
timeout: 100
|
|
113
|
-
}, (err
|
|
113
|
+
}, (err) => {
|
|
114
114
|
t.equal(err.message, 'Request timed out')
|
|
115
115
|
})
|
|
116
116
|
})
|
|
@@ -126,14 +126,14 @@ test('POST request with form body and body-parser hangs up, compatibility case',
|
|
|
126
126
|
fastify.register(expressPlugin, { expressHook: 'preHandler' })
|
|
127
127
|
.after(() => {
|
|
128
128
|
fastify.use(express)
|
|
129
|
-
fastify.use((req,
|
|
129
|
+
fastify.use((req, _res, next) => {
|
|
130
130
|
// fastify-formbody with backward compatibility result
|
|
131
131
|
t.same(req.body, { input: 'test' })
|
|
132
132
|
next()
|
|
133
133
|
})
|
|
134
134
|
})
|
|
135
135
|
|
|
136
|
-
fastify.post('/hello', (
|
|
136
|
+
fastify.post('/hello', () => {
|
|
137
137
|
return { hello: 'world' }
|
|
138
138
|
})
|
|
139
139
|
|
package/test/hooks.test.js
CHANGED
|
@@ -10,7 +10,7 @@ test('onSend hook should receive valid request and reply objects if middleware f
|
|
|
10
10
|
const fastify = Fastify()
|
|
11
11
|
fastify.register(expressPlugin)
|
|
12
12
|
.after(() => {
|
|
13
|
-
fastify.use(function (
|
|
13
|
+
fastify.use(function (_req, _res, next) {
|
|
14
14
|
next(new Error('middlware failed'))
|
|
15
15
|
})
|
|
16
16
|
})
|
|
@@ -18,13 +18,13 @@ test('onSend hook should receive valid request and reply objects if middleware f
|
|
|
18
18
|
fastify.decorateRequest('testDecorator', 'testDecoratorVal')
|
|
19
19
|
fastify.decorateReply('testDecorator', 'testDecoratorVal')
|
|
20
20
|
|
|
21
|
-
fastify.addHook('onSend', function (request, reply,
|
|
21
|
+
fastify.addHook('onSend', function (request, reply, _payload, next) {
|
|
22
22
|
t.equal(request.testDecorator, 'testDecoratorVal')
|
|
23
23
|
t.equal(reply.testDecorator, 'testDecoratorVal')
|
|
24
24
|
next()
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
fastify.get('/', (
|
|
27
|
+
fastify.get('/', (_req, reply) => {
|
|
28
28
|
reply.send('hello')
|
|
29
29
|
})
|
|
30
30
|
|
|
@@ -56,7 +56,7 @@ test('request.url is not mutated between onRequest and onResponse', t => {
|
|
|
56
56
|
const mainRouter = express.Router()
|
|
57
57
|
const innerRouter = express.Router()
|
|
58
58
|
mainRouter.use('/hubba', innerRouter)
|
|
59
|
-
innerRouter.get('/bubba', (
|
|
59
|
+
innerRouter.get('/bubba', (_req, res) => {
|
|
60
60
|
res.sendStatus(200)
|
|
61
61
|
})
|
|
62
62
|
fastify.use(mainRouter)
|