fastify 5.11.2 → 6.0.0-alpha.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 +9 -9
- package/SPONSORS.md +1 -0
- package/build/build-validation.js +20 -34
- package/docs/Guides/Getting-Started.md +2 -2
- package/docs/Guides/Serverless.md +34 -2
- package/docs/Reference/Encapsulation.md +31 -2
- package/docs/Reference/Errors.md +81 -6
- package/docs/Reference/Hooks.md +0 -4
- package/docs/Reference/LTS.md +6 -5
- package/docs/Reference/Request.md +18 -6
- package/docs/Reference/Routes.md +13 -0
- package/docs/Reference/Server.md +8 -88
- package/docs/Reference/TypeScript.md +3 -49
- package/docs/Reference/Warnings.md +4 -11
- package/fastify.d.ts +10 -24
- package/fastify.js +17 -34
- package/lib/config-validator.js +368 -475
- package/lib/content-type-parser.js +4 -0
- package/lib/decorate.js +1 -1
- package/lib/errors.js +9 -3
- package/lib/log-controller.js +3 -5
- package/lib/logger-factory.js +1 -1
- package/lib/reply.js +7 -3
- package/lib/route.js +4 -9
- package/lib/server.js +2 -3
- package/lib/warnings.js +2 -46
- package/package.json +2 -3
- package/test/404s.test.js +0 -49
- package/test/allow-unsafe-regex.test.js +12 -4
- package/test/case-insensitive.test.js +12 -4
- package/test/content-parser.test.js +32 -0
- package/test/custom-querystring-parser.test.js +0 -16
- package/test/decorator-instance-properties.test.js +49 -0
- package/test/hooks.test.js +6 -1
- package/test/http-methods/custom-http-methods.test.js +12 -17
- package/test/http-methods/trace.test.js +1 -1
- package/test/https/custom-https-server.test.js +1 -1
- package/test/internals/errors.test.js +15 -5
- package/test/internals/initial-config.test.js +56 -38
- package/test/internals/logger.test.js +17 -4
- package/test/internals/reply.test.js +1 -1
- package/test/internals/request.test.js +8 -24
- package/test/logger/logging.test.js +2 -121
- package/test/logger/request.test.js +1 -36
- package/test/plugin.4.test.js +5 -4
- package/test/reply-trailers.test.js +92 -4
- package/test/route-prefix.test.js +46 -18
- package/test/route.1.test.js +2 -2
- package/test/router-options.test.js +25 -523
- package/test/set-error-handler.test.js +7 -9
- package/test/types/errors.tst.ts +2 -1
- package/test/types/fastify.tst.ts +44 -48
- package/test/types/instance.tst.ts +4 -5
- package/test/types/logger.tst.ts +3 -7
- package/test/use-semicolon-delimiter.test.js +0 -60
- package/types/context.d.ts +0 -20
- package/types/errors.d.ts +2 -1
- package/types/instance.d.ts +0 -4
- package/types/logger.d.ts +2 -17
- package/types/plugin.d.ts +0 -9
- package/types/request.d.ts +0 -4
- package/.pi/bash-confirm-whitelist.json +0 -180
- package/lib/promise.js +0 -23
- package/test/internals/promise.test.js +0 -63
|
@@ -13,7 +13,9 @@ const {
|
|
|
13
13
|
test('Should honor ignoreTrailingSlash option', async t => {
|
|
14
14
|
t.plan(4)
|
|
15
15
|
const fastify = Fastify({
|
|
16
|
-
|
|
16
|
+
routerOptions: {
|
|
17
|
+
ignoreTrailingSlash: true
|
|
18
|
+
}
|
|
17
19
|
})
|
|
18
20
|
|
|
19
21
|
fastify.get('/test', (req, res) => {
|
|
@@ -32,7 +34,9 @@ test('Should honor ignoreTrailingSlash option', async t => {
|
|
|
32
34
|
test('Should honor ignoreDuplicateSlashes option', async t => {
|
|
33
35
|
t.plan(4)
|
|
34
36
|
const fastify = Fastify({
|
|
35
|
-
|
|
37
|
+
routerOptions: {
|
|
38
|
+
ignoreDuplicateSlashes: true
|
|
39
|
+
}
|
|
36
40
|
})
|
|
37
41
|
|
|
38
42
|
fastify.get('/test//test///test', (req, res) => {
|
|
@@ -51,8 +55,10 @@ test('Should honor ignoreDuplicateSlashes option', async t => {
|
|
|
51
55
|
test('Should honor ignoreTrailingSlash and ignoreDuplicateSlashes options', async t => {
|
|
52
56
|
t.plan(4)
|
|
53
57
|
const fastify = Fastify({
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
routerOptions: {
|
|
59
|
+
ignoreTrailingSlash: true,
|
|
60
|
+
ignoreDuplicateSlashes: true
|
|
61
|
+
}
|
|
56
62
|
})
|
|
57
63
|
|
|
58
64
|
fastify.get('/test//test///test', (req, res) => {
|
|
@@ -219,54 +225,12 @@ test('Should supply Fastify request to the logger in frameworkErrors wrapper - F
|
|
|
219
225
|
)
|
|
220
226
|
})
|
|
221
227
|
|
|
222
|
-
test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST_ERR_BAD_URL', (t, done) => {
|
|
223
|
-
t.plan(2)
|
|
224
|
-
|
|
225
|
-
const logStream = split(JSON.parse)
|
|
226
|
-
|
|
227
|
-
const fastify = Fastify({
|
|
228
|
-
disableRequestLogging: true,
|
|
229
|
-
frameworkErrors: function (err, req, res) {
|
|
230
|
-
res.send(`${err.message} - ${err.code}`)
|
|
231
|
-
},
|
|
232
|
-
logger: {
|
|
233
|
-
stream: logStream,
|
|
234
|
-
serializers: {
|
|
235
|
-
req () {
|
|
236
|
-
t.assert.fail('should not be called')
|
|
237
|
-
},
|
|
238
|
-
res () {
|
|
239
|
-
t.assert.fail('should not be called')
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
fastify.get('/test/:id', (req, res) => {
|
|
246
|
-
res.send('{ hello: \'world\' }')
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
logStream.on('data', (json) => {
|
|
250
|
-
t.assert.fail('should not be called')
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
fastify.inject(
|
|
254
|
-
{
|
|
255
|
-
method: 'GET',
|
|
256
|
-
url: '/test/%world'
|
|
257
|
-
},
|
|
258
|
-
(err, res) => {
|
|
259
|
-
t.assert.ifError(err)
|
|
260
|
-
t.assert.strictEqual(res.body, '\'/test/%world\' is not a valid url component - FST_ERR_BAD_URL')
|
|
261
|
-
done()
|
|
262
|
-
}
|
|
263
|
-
)
|
|
264
|
-
})
|
|
265
|
-
|
|
266
228
|
test('Should honor frameworkErrors option - FST_ERR_MAX_PARAM_LENGTH', (t, done) => {
|
|
267
229
|
t.plan(3)
|
|
268
230
|
const fastify = Fastify({
|
|
269
|
-
|
|
231
|
+
routerOptions: {
|
|
232
|
+
maxParamLength: 1
|
|
233
|
+
},
|
|
270
234
|
frameworkErrors: function (err, req, res) {
|
|
271
235
|
if (err instanceof FST_ERR_MAX_PARAM_LENGTH) {
|
|
272
236
|
t.assert.ok(true)
|
|
@@ -301,7 +265,9 @@ test('Should supply Fastify request to the logger in frameworkErrors wrapper - F
|
|
|
301
265
|
const logStream = split(JSON.parse)
|
|
302
266
|
|
|
303
267
|
const fastify = Fastify({
|
|
304
|
-
|
|
268
|
+
routerOptions: {
|
|
269
|
+
maxParamLength: 1
|
|
270
|
+
},
|
|
305
271
|
frameworkErrors: function (err, req, res) {
|
|
306
272
|
t.assert.deepStrictEqual(req.id, REQ_ID)
|
|
307
273
|
t.assert.deepStrictEqual(req.raw.httpVersion, '1.1')
|
|
@@ -342,51 +308,6 @@ test('Should supply Fastify request to the logger in frameworkErrors wrapper - F
|
|
|
342
308
|
)
|
|
343
309
|
})
|
|
344
310
|
|
|
345
|
-
test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST_ERR_MAX_PARAM_LENGTH', (t, done) => {
|
|
346
|
-
t.plan(2)
|
|
347
|
-
|
|
348
|
-
const logStream = split(JSON.parse)
|
|
349
|
-
|
|
350
|
-
const fastify = Fastify({
|
|
351
|
-
disableRequestLogging: true,
|
|
352
|
-
maxParamLength: 1,
|
|
353
|
-
frameworkErrors: function (err, req, res) {
|
|
354
|
-
res.send(`${err.message} - ${err.code}`)
|
|
355
|
-
},
|
|
356
|
-
logger: {
|
|
357
|
-
stream: logStream,
|
|
358
|
-
serializers: {
|
|
359
|
-
req () {
|
|
360
|
-
t.assert.fail('should not be called')
|
|
361
|
-
},
|
|
362
|
-
res () {
|
|
363
|
-
t.assert.fail('should not be called')
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
})
|
|
368
|
-
|
|
369
|
-
fastify.get('/test/:id', (req, res) => {
|
|
370
|
-
res.send('{ hello: \'world\' }')
|
|
371
|
-
})
|
|
372
|
-
|
|
373
|
-
logStream.on('data', (json) => {
|
|
374
|
-
t.assert.fail('should not be called')
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
fastify.inject(
|
|
378
|
-
{
|
|
379
|
-
method: 'GET',
|
|
380
|
-
url: '/test/123'
|
|
381
|
-
},
|
|
382
|
-
(err, res) => {
|
|
383
|
-
t.assert.ifError(err)
|
|
384
|
-
t.assert.strictEqual(res.body, '\'/test/123\' is exceeding the max param length - FST_ERR_MAX_PARAM_LENGTH')
|
|
385
|
-
done()
|
|
386
|
-
}
|
|
387
|
-
)
|
|
388
|
-
})
|
|
389
|
-
|
|
390
311
|
test('Should honor frameworkErrors option - FST_ERR_ASYNC_CONSTRAINT', (t, done) => {
|
|
391
312
|
t.plan(3)
|
|
392
313
|
|
|
@@ -507,283 +428,6 @@ test('Should supply Fastify request to the logger in frameworkErrors wrapper - F
|
|
|
507
428
|
)
|
|
508
429
|
})
|
|
509
430
|
|
|
510
|
-
test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST_ERR_ASYNC_CONSTRAINT', (t, done) => {
|
|
511
|
-
t.plan(2)
|
|
512
|
-
|
|
513
|
-
const constraint = {
|
|
514
|
-
name: 'secret',
|
|
515
|
-
storage: function () {
|
|
516
|
-
const secrets = {}
|
|
517
|
-
return {
|
|
518
|
-
get: (secret) => { return secrets[secret] || null },
|
|
519
|
-
set: (secret, store) => { secrets[secret] = store }
|
|
520
|
-
}
|
|
521
|
-
},
|
|
522
|
-
deriveConstraint: (req, ctx, done) => {
|
|
523
|
-
done(Error('kaboom'))
|
|
524
|
-
},
|
|
525
|
-
validate () { return true }
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
const logStream = split(JSON.parse)
|
|
529
|
-
|
|
530
|
-
const fastify = Fastify({
|
|
531
|
-
constraints: { secret: constraint },
|
|
532
|
-
disableRequestLogging: true,
|
|
533
|
-
frameworkErrors: function (err, req, res) {
|
|
534
|
-
res.send(`${err.message} - ${err.code}`)
|
|
535
|
-
},
|
|
536
|
-
logger: {
|
|
537
|
-
stream: logStream,
|
|
538
|
-
serializers: {
|
|
539
|
-
req () {
|
|
540
|
-
t.assert.fail('should not be called')
|
|
541
|
-
},
|
|
542
|
-
res () {
|
|
543
|
-
t.assert.fail('should not be called')
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
})
|
|
548
|
-
|
|
549
|
-
fastify.route({
|
|
550
|
-
method: 'GET',
|
|
551
|
-
url: '/',
|
|
552
|
-
constraints: { secret: 'alpha' },
|
|
553
|
-
handler: (req, reply) => {
|
|
554
|
-
reply.send({ hello: 'from alpha' })
|
|
555
|
-
}
|
|
556
|
-
})
|
|
557
|
-
|
|
558
|
-
logStream.on('data', (json) => {
|
|
559
|
-
t.assert.fail('should not be called')
|
|
560
|
-
})
|
|
561
|
-
|
|
562
|
-
fastify.inject(
|
|
563
|
-
{
|
|
564
|
-
method: 'GET',
|
|
565
|
-
url: '/'
|
|
566
|
-
},
|
|
567
|
-
(err, res) => {
|
|
568
|
-
t.assert.ifError(err)
|
|
569
|
-
t.assert.strictEqual(res.body, 'Unexpected error from async constraint - FST_ERR_ASYNC_CONSTRAINT')
|
|
570
|
-
done()
|
|
571
|
-
}
|
|
572
|
-
)
|
|
573
|
-
})
|
|
574
|
-
|
|
575
|
-
test('Should honor disableRequestLogging function in frameworkErrors wrapper - FST_ERR_BAD_URL', (t, done) => {
|
|
576
|
-
t.plan(4)
|
|
577
|
-
|
|
578
|
-
let logCallCount = 0
|
|
579
|
-
const logStream = split(JSON.parse)
|
|
580
|
-
|
|
581
|
-
const fastify = Fastify({
|
|
582
|
-
disableRequestLogging: (req) => {
|
|
583
|
-
// Disable logging for URLs containing 'silent'
|
|
584
|
-
return req.url.includes('silent')
|
|
585
|
-
},
|
|
586
|
-
frameworkErrors: function (err, req, res) {
|
|
587
|
-
res.send(`${err.message} - ${err.code}`)
|
|
588
|
-
},
|
|
589
|
-
logger: {
|
|
590
|
-
stream: logStream,
|
|
591
|
-
level: 'info'
|
|
592
|
-
}
|
|
593
|
-
})
|
|
594
|
-
|
|
595
|
-
fastify.get('/test/:id', (req, res) => {
|
|
596
|
-
res.send('{ hello: \'world\' }')
|
|
597
|
-
})
|
|
598
|
-
|
|
599
|
-
logStream.on('data', (json) => {
|
|
600
|
-
if (json.msg === 'incoming request') {
|
|
601
|
-
logCallCount++
|
|
602
|
-
}
|
|
603
|
-
})
|
|
604
|
-
|
|
605
|
-
// First request: URL does not contain 'silent', so logging should happen
|
|
606
|
-
fastify.inject(
|
|
607
|
-
{
|
|
608
|
-
method: 'GET',
|
|
609
|
-
url: '/test/%world'
|
|
610
|
-
},
|
|
611
|
-
(err, res) => {
|
|
612
|
-
t.assert.ifError(err)
|
|
613
|
-
t.assert.strictEqual(res.body, '\'/test/%world\' is not a valid url component - FST_ERR_BAD_URL')
|
|
614
|
-
|
|
615
|
-
// Second request: URL contains 'silent', so logging should be disabled
|
|
616
|
-
fastify.inject(
|
|
617
|
-
{
|
|
618
|
-
method: 'GET',
|
|
619
|
-
url: '/silent/%world'
|
|
620
|
-
},
|
|
621
|
-
(err2, res2) => {
|
|
622
|
-
t.assert.ifError(err2)
|
|
623
|
-
// Give time for any potential log events
|
|
624
|
-
setImmediate(() => {
|
|
625
|
-
// Only the first request should have logged
|
|
626
|
-
t.assert.strictEqual(logCallCount, 1)
|
|
627
|
-
done()
|
|
628
|
-
})
|
|
629
|
-
}
|
|
630
|
-
)
|
|
631
|
-
}
|
|
632
|
-
)
|
|
633
|
-
})
|
|
634
|
-
|
|
635
|
-
test('Should honor disableRequestLogging function in frameworkErrors wrapper - FST_ERR_MAX_PARAM_LENGTH', (t, done) => {
|
|
636
|
-
t.plan(4)
|
|
637
|
-
|
|
638
|
-
let logCallCount = 0
|
|
639
|
-
const logStream = split(JSON.parse)
|
|
640
|
-
|
|
641
|
-
const fastify = Fastify({
|
|
642
|
-
maxParamLength: 1,
|
|
643
|
-
disableRequestLogging: (req) => {
|
|
644
|
-
// Disable logging for URLs containing 'silent'
|
|
645
|
-
return req.url.includes('silent')
|
|
646
|
-
},
|
|
647
|
-
frameworkErrors: function (err, req, res) {
|
|
648
|
-
res.send(`${err.message} - ${err.code}`)
|
|
649
|
-
},
|
|
650
|
-
logger: {
|
|
651
|
-
stream: logStream,
|
|
652
|
-
level: 'info'
|
|
653
|
-
}
|
|
654
|
-
})
|
|
655
|
-
|
|
656
|
-
fastify.get('/test/:id', (req, res) => {
|
|
657
|
-
res.send('{ hello: \'world\' }')
|
|
658
|
-
})
|
|
659
|
-
|
|
660
|
-
logStream.on('data', (json) => {
|
|
661
|
-
if (json.msg === 'incoming request') {
|
|
662
|
-
logCallCount++
|
|
663
|
-
}
|
|
664
|
-
})
|
|
665
|
-
|
|
666
|
-
// First request: URL does not contain 'silent', so logging should happen
|
|
667
|
-
fastify.inject(
|
|
668
|
-
{
|
|
669
|
-
method: 'GET',
|
|
670
|
-
url: '/test/123'
|
|
671
|
-
},
|
|
672
|
-
(err, res) => {
|
|
673
|
-
t.assert.ifError(err)
|
|
674
|
-
t.assert.strictEqual(res.body, '\'/test/123\' is exceeding the max param length - FST_ERR_MAX_PARAM_LENGTH')
|
|
675
|
-
|
|
676
|
-
// Second request: URL contains 'silent', so logging should be disabled
|
|
677
|
-
fastify.inject(
|
|
678
|
-
{
|
|
679
|
-
method: 'GET',
|
|
680
|
-
url: '/silent/123'
|
|
681
|
-
},
|
|
682
|
-
(err2, res2) => {
|
|
683
|
-
t.assert.ifError(err2)
|
|
684
|
-
// Give time for any potential log events
|
|
685
|
-
setImmediate(() => {
|
|
686
|
-
// Only the first request should have logged
|
|
687
|
-
t.assert.strictEqual(logCallCount, 1)
|
|
688
|
-
done()
|
|
689
|
-
})
|
|
690
|
-
}
|
|
691
|
-
)
|
|
692
|
-
}
|
|
693
|
-
)
|
|
694
|
-
})
|
|
695
|
-
|
|
696
|
-
test('Should honor disableRequestLogging function in frameworkErrors wrapper - FST_ERR_ASYNC_CONSTRAINT', (t, done) => {
|
|
697
|
-
t.plan(4)
|
|
698
|
-
|
|
699
|
-
let logCallCount = 0
|
|
700
|
-
|
|
701
|
-
const constraint = {
|
|
702
|
-
name: 'secret',
|
|
703
|
-
storage: function () {
|
|
704
|
-
const secrets = {}
|
|
705
|
-
return {
|
|
706
|
-
get: (secret) => { return secrets[secret] || null },
|
|
707
|
-
set: (secret, store) => { secrets[secret] = store }
|
|
708
|
-
}
|
|
709
|
-
},
|
|
710
|
-
deriveConstraint: (req, ctx, done) => {
|
|
711
|
-
done(Error('kaboom'))
|
|
712
|
-
},
|
|
713
|
-
validate () { return true }
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
const logStream = split(JSON.parse)
|
|
717
|
-
|
|
718
|
-
const fastify = Fastify({
|
|
719
|
-
constraints: { secret: constraint },
|
|
720
|
-
disableRequestLogging: (req) => {
|
|
721
|
-
// Disable logging for URLs containing 'silent'
|
|
722
|
-
return req.url.includes('silent')
|
|
723
|
-
},
|
|
724
|
-
frameworkErrors: function (err, req, res) {
|
|
725
|
-
res.send(`${err.message} - ${err.code}`)
|
|
726
|
-
},
|
|
727
|
-
logger: {
|
|
728
|
-
stream: logStream,
|
|
729
|
-
level: 'info'
|
|
730
|
-
}
|
|
731
|
-
})
|
|
732
|
-
|
|
733
|
-
fastify.route({
|
|
734
|
-
method: 'GET',
|
|
735
|
-
url: '/',
|
|
736
|
-
constraints: { secret: 'alpha' },
|
|
737
|
-
handler: (req, reply) => {
|
|
738
|
-
reply.send({ hello: 'from alpha' })
|
|
739
|
-
}
|
|
740
|
-
})
|
|
741
|
-
|
|
742
|
-
fastify.route({
|
|
743
|
-
method: 'GET',
|
|
744
|
-
url: '/silent',
|
|
745
|
-
constraints: { secret: 'alpha' },
|
|
746
|
-
handler: (req, reply) => {
|
|
747
|
-
reply.send({ hello: 'from alpha' })
|
|
748
|
-
}
|
|
749
|
-
})
|
|
750
|
-
|
|
751
|
-
logStream.on('data', (json) => {
|
|
752
|
-
if (json.msg === 'incoming request') {
|
|
753
|
-
logCallCount++
|
|
754
|
-
}
|
|
755
|
-
})
|
|
756
|
-
|
|
757
|
-
// First request: URL does not contain 'silent', so logging should happen
|
|
758
|
-
fastify.inject(
|
|
759
|
-
{
|
|
760
|
-
method: 'GET',
|
|
761
|
-
url: '/'
|
|
762
|
-
},
|
|
763
|
-
(err, res) => {
|
|
764
|
-
t.assert.ifError(err)
|
|
765
|
-
t.assert.strictEqual(res.body, 'Unexpected error from async constraint - FST_ERR_ASYNC_CONSTRAINT')
|
|
766
|
-
|
|
767
|
-
// Second request: URL contains 'silent', so logging should be disabled
|
|
768
|
-
fastify.inject(
|
|
769
|
-
{
|
|
770
|
-
method: 'GET',
|
|
771
|
-
url: '/silent'
|
|
772
|
-
},
|
|
773
|
-
(err2, res2) => {
|
|
774
|
-
t.assert.ifError(err2)
|
|
775
|
-
// Give time for any potential log events
|
|
776
|
-
setImmediate(() => {
|
|
777
|
-
// Only the first request should have logged
|
|
778
|
-
t.assert.strictEqual(logCallCount, 1)
|
|
779
|
-
done()
|
|
780
|
-
})
|
|
781
|
-
}
|
|
782
|
-
)
|
|
783
|
-
}
|
|
784
|
-
)
|
|
785
|
-
})
|
|
786
|
-
|
|
787
431
|
test('Should honor routerOptions.defaultRoute', async t => {
|
|
788
432
|
t.plan(3)
|
|
789
433
|
const fastify = Fastify({
|
|
@@ -918,8 +562,7 @@ test('Should honor routerOptions.ignoreTrailingSlash and routerOptions.ignoreDup
|
|
|
918
562
|
|
|
919
563
|
test('Should honor routerOptions.maxParamLength', async (t) => {
|
|
920
564
|
const fastify = Fastify({
|
|
921
|
-
routerOptions:
|
|
922
|
-
{
|
|
565
|
+
routerOptions: {
|
|
923
566
|
maxParamLength: 10
|
|
924
567
|
}
|
|
925
568
|
})
|
|
@@ -943,8 +586,7 @@ test('Should honor routerOptions.maxParamLength', async (t) => {
|
|
|
943
586
|
|
|
944
587
|
test('Should honor routerOptions.allowUnsafeRegex', async (t) => {
|
|
945
588
|
const fastify = Fastify({
|
|
946
|
-
routerOptions:
|
|
947
|
-
{
|
|
589
|
+
routerOptions: {
|
|
948
590
|
allowUnsafeRegex: true
|
|
949
591
|
}
|
|
950
592
|
})
|
|
@@ -969,8 +611,7 @@ test('Should honor routerOptions.allowUnsafeRegex', async (t) => {
|
|
|
969
611
|
|
|
970
612
|
test('Should honor routerOptions.caseSensitive', async (t) => {
|
|
971
613
|
const fastify = Fastify({
|
|
972
|
-
routerOptions:
|
|
973
|
-
{
|
|
614
|
+
routerOptions: {
|
|
974
615
|
caseSensitive: false
|
|
975
616
|
}
|
|
976
617
|
})
|
|
@@ -1026,8 +667,7 @@ test('Should honor routerOptions.queryStringParser', async (t) => {
|
|
|
1026
667
|
test('Should honor routerOptions.useSemicolonDelimiter', async (t) => {
|
|
1027
668
|
t.plan(6)
|
|
1028
669
|
const fastify = Fastify({
|
|
1029
|
-
routerOptions:
|
|
1030
|
-
{
|
|
670
|
+
routerOptions: {
|
|
1031
671
|
useSemicolonDelimiter: true
|
|
1032
672
|
}
|
|
1033
673
|
})
|
|
@@ -1092,115 +732,6 @@ test('Should honor routerOptions.buildPrettyMeta', async (t) => {
|
|
|
1092
732
|
t.assert.strictEqual(result, expected)
|
|
1093
733
|
})
|
|
1094
734
|
|
|
1095
|
-
test('Should honor routerOptions.ignoreTrailingSlash and routerOptions.ignoreDuplicateSlashes over top level options', async t => {
|
|
1096
|
-
t.plan(4)
|
|
1097
|
-
const fastify = Fastify({
|
|
1098
|
-
ignoreTrailingSlash: false,
|
|
1099
|
-
ignoreDuplicateSlashes: false,
|
|
1100
|
-
routerOptions: {
|
|
1101
|
-
ignoreTrailingSlash: true,
|
|
1102
|
-
ignoreDuplicateSlashes: true
|
|
1103
|
-
}
|
|
1104
|
-
})
|
|
1105
|
-
|
|
1106
|
-
fastify.get('/test//test///test', (req, res) => {
|
|
1107
|
-
res.send('test')
|
|
1108
|
-
})
|
|
1109
|
-
|
|
1110
|
-
let res = await fastify.inject('/test/test/test/')
|
|
1111
|
-
t.assert.strictEqual(res.statusCode, 200)
|
|
1112
|
-
t.assert.strictEqual(res.payload.toString(), 'test')
|
|
1113
|
-
|
|
1114
|
-
res = await fastify.inject('/test//test///test//')
|
|
1115
|
-
t.assert.strictEqual(res.statusCode, 200)
|
|
1116
|
-
t.assert.strictEqual(res.payload.toString(), 'test')
|
|
1117
|
-
})
|
|
1118
|
-
|
|
1119
|
-
test('Should honor routerOptions.maxParamLength over maxParamLength option', async (t) => {
|
|
1120
|
-
const fastify = Fastify({
|
|
1121
|
-
maxParamLength: 0,
|
|
1122
|
-
routerOptions:
|
|
1123
|
-
{
|
|
1124
|
-
maxParamLength: 10
|
|
1125
|
-
}
|
|
1126
|
-
})
|
|
1127
|
-
|
|
1128
|
-
fastify.get('/test/:id', (req, reply) => {
|
|
1129
|
-
reply.send({ hello: 'world' })
|
|
1130
|
-
})
|
|
1131
|
-
|
|
1132
|
-
const res = await fastify.inject({
|
|
1133
|
-
method: 'GET',
|
|
1134
|
-
url: '/test/123456789'
|
|
1135
|
-
})
|
|
1136
|
-
t.assert.strictEqual(res.statusCode, 200)
|
|
1137
|
-
|
|
1138
|
-
const resError = await fastify.inject({
|
|
1139
|
-
method: 'GET',
|
|
1140
|
-
url: '/test/123456789abcd'
|
|
1141
|
-
})
|
|
1142
|
-
t.assert.strictEqual(resError.statusCode, 414)
|
|
1143
|
-
})
|
|
1144
|
-
|
|
1145
|
-
test('Should honor routerOptions.allowUnsafeRegex over allowUnsafeRegex option', async (t) => {
|
|
1146
|
-
const fastify = Fastify({
|
|
1147
|
-
allowUnsafeRegex: false,
|
|
1148
|
-
routerOptions:
|
|
1149
|
-
{
|
|
1150
|
-
allowUnsafeRegex: true
|
|
1151
|
-
}
|
|
1152
|
-
})
|
|
1153
|
-
|
|
1154
|
-
fastify.get('/test/:id(([a-f0-9]{3},?)+)', (req, reply) => {
|
|
1155
|
-
reply.send({ hello: 'world' })
|
|
1156
|
-
})
|
|
1157
|
-
|
|
1158
|
-
let res = await fastify.inject({
|
|
1159
|
-
method: 'GET',
|
|
1160
|
-
url: '/test/bac,1ea'
|
|
1161
|
-
})
|
|
1162
|
-
t.assert.strictEqual(res.statusCode, 200)
|
|
1163
|
-
|
|
1164
|
-
res = await fastify.inject({
|
|
1165
|
-
method: 'GET',
|
|
1166
|
-
url: '/test/qwerty'
|
|
1167
|
-
})
|
|
1168
|
-
|
|
1169
|
-
t.assert.strictEqual(res.statusCode, 404)
|
|
1170
|
-
})
|
|
1171
|
-
|
|
1172
|
-
test('Should honor routerOptions.caseSensitive over caseSensitive option', async (t) => {
|
|
1173
|
-
const fastify = Fastify({
|
|
1174
|
-
caseSensitive: true,
|
|
1175
|
-
routerOptions:
|
|
1176
|
-
{
|
|
1177
|
-
caseSensitive: false
|
|
1178
|
-
}
|
|
1179
|
-
})
|
|
1180
|
-
|
|
1181
|
-
fastify.get('/TeSt', (req, reply) => {
|
|
1182
|
-
reply.send('test')
|
|
1183
|
-
})
|
|
1184
|
-
|
|
1185
|
-
let res = await fastify.inject({
|
|
1186
|
-
method: 'GET',
|
|
1187
|
-
url: '/test'
|
|
1188
|
-
})
|
|
1189
|
-
t.assert.strictEqual(res.statusCode, 200)
|
|
1190
|
-
|
|
1191
|
-
res = await fastify.inject({
|
|
1192
|
-
method: 'GET',
|
|
1193
|
-
url: '/tEsT'
|
|
1194
|
-
})
|
|
1195
|
-
t.assert.strictEqual(res.statusCode, 200)
|
|
1196
|
-
|
|
1197
|
-
res = await fastify.inject({
|
|
1198
|
-
method: 'GET',
|
|
1199
|
-
url: '/TEST'
|
|
1200
|
-
})
|
|
1201
|
-
t.assert.strictEqual(res.statusCode, 200)
|
|
1202
|
-
})
|
|
1203
|
-
|
|
1204
735
|
test('Should honor routerOptions.queryStringParser over queryStringParser option', async (t) => {
|
|
1205
736
|
t.plan(4)
|
|
1206
737
|
const fastify = Fastify({
|
|
@@ -1227,55 +758,26 @@ test('Should honor routerOptions.queryStringParser over queryStringParser option
|
|
|
1227
758
|
t.assert.strictEqual(res.statusCode, 200)
|
|
1228
759
|
})
|
|
1229
760
|
|
|
1230
|
-
test('Should honor routerOptions.useSemicolonDelimiter over useSemicolonDelimiter option', async (t) => {
|
|
1231
|
-
t.plan(6)
|
|
1232
|
-
const fastify = Fastify({
|
|
1233
|
-
useSemicolonDelimiter: false,
|
|
1234
|
-
routerOptions:
|
|
1235
|
-
{
|
|
1236
|
-
useSemicolonDelimiter: true
|
|
1237
|
-
}
|
|
1238
|
-
})
|
|
1239
|
-
|
|
1240
|
-
fastify.get('/test', (req, reply) => {
|
|
1241
|
-
t.assert.deepStrictEqual(req.query.foo, 'bar')
|
|
1242
|
-
t.assert.deepStrictEqual(req.query.baz, 'faz')
|
|
1243
|
-
reply.send('test')
|
|
1244
|
-
})
|
|
1245
|
-
|
|
1246
|
-
// Support semicolon delimiter
|
|
1247
|
-
let res = await fastify.inject({
|
|
1248
|
-
method: 'GET',
|
|
1249
|
-
url: '/test;foo=bar&baz=faz'
|
|
1250
|
-
})
|
|
1251
|
-
t.assert.strictEqual(res.statusCode, 200)
|
|
1252
|
-
|
|
1253
|
-
// Support query string `?` delimiter
|
|
1254
|
-
res = await fastify.inject({
|
|
1255
|
-
method: 'GET',
|
|
1256
|
-
url: '/test?foo=bar&baz=faz'
|
|
1257
|
-
})
|
|
1258
|
-
t.assert.strictEqual(res.statusCode, 200)
|
|
1259
|
-
})
|
|
1260
|
-
|
|
1261
761
|
test('Should support extra find-my-way options', async t => {
|
|
1262
762
|
t.plan(1)
|
|
763
|
+
let run = false
|
|
1263
764
|
// Use a real upstream option from find-my-way
|
|
1264
765
|
const fastify = Fastify({
|
|
1265
766
|
routerOptions: {
|
|
1266
767
|
buildPrettyMeta: (route) => {
|
|
768
|
+
run = true
|
|
1267
769
|
const cleanMeta = Object.assign({}, route.store)
|
|
1268
770
|
return cleanMeta
|
|
1269
771
|
}
|
|
1270
772
|
}
|
|
1271
773
|
})
|
|
774
|
+
fastify.get('/', async () => ({ ok: true }))
|
|
1272
775
|
|
|
1273
776
|
t.after(() => fastify.close())
|
|
1274
777
|
|
|
1275
778
|
await fastify.ready()
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
t.assert.strictEqual(typeof fastify.initialConfig.routerOptions.buildPrettyMeta, 'function')
|
|
779
|
+
fastify.printRoutes({ includeMeta: true })
|
|
780
|
+
t.assert.strictEqual(run, true)
|
|
1279
781
|
})
|
|
1280
782
|
|
|
1281
783
|
test('Should allow reusing a routerOptions object across instances', async t => {
|
|
@@ -27,7 +27,9 @@ test('setErrorHandler can be set independently in parent and child scopes', asyn
|
|
|
27
27
|
test('setErrorHandler can be overridden if allowErrorHandlerOverride is set to true', async t => {
|
|
28
28
|
t.plan(2)
|
|
29
29
|
|
|
30
|
-
const fastify = Fastify(
|
|
30
|
+
const fastify = Fastify({
|
|
31
|
+
allowErrorHandlerOverride: true
|
|
32
|
+
})
|
|
31
33
|
t.after(() => fastify.close())
|
|
32
34
|
|
|
33
35
|
fastify.register(async (child) => {
|
|
@@ -41,23 +43,19 @@ test('setErrorHandler can be overridden if allowErrorHandlerOverride is set to t
|
|
|
41
43
|
await fastify.ready()
|
|
42
44
|
})
|
|
43
45
|
|
|
44
|
-
test('
|
|
46
|
+
test('setErrorHandler should throw by default if called more than once in the same scope', t => {
|
|
45
47
|
t.plan(1)
|
|
46
48
|
|
|
47
|
-
const fastify = Fastify(
|
|
48
|
-
allowErrorHandlerOverride: false
|
|
49
|
-
})
|
|
49
|
+
const fastify = Fastify()
|
|
50
50
|
|
|
51
51
|
fastify.setErrorHandler(() => {})
|
|
52
52
|
t.assert.throws(() => fastify.setErrorHandler(() => {}), new FST_ERR_ERROR_HANDLER_ALREADY_SET())
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
test('
|
|
55
|
+
test('setErrorHandler should throw by default if called more than once in a child scope', async t => {
|
|
56
56
|
t.plan(1)
|
|
57
57
|
|
|
58
|
-
const fastify = Fastify(
|
|
59
|
-
allowErrorHandlerOverride: false
|
|
60
|
-
})
|
|
58
|
+
const fastify = Fastify()
|
|
61
59
|
t.after(() => fastify.close())
|
|
62
60
|
|
|
63
61
|
fastify.register(async (child) => {
|
package/test/types/errors.tst.ts
CHANGED
|
@@ -73,6 +73,7 @@ expect(errorCodes.FST_ERR_ROUTE_DUPLICATED_HANDLER).type.toBeAssignableTo<Fastif
|
|
|
73
73
|
expect(errorCodes.FST_ERR_ROUTE_HANDLER_NOT_FN).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
74
74
|
expect(errorCodes.FST_ERR_ROUTE_MISSING_HANDLER).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
75
75
|
expect(errorCodes.FST_ERR_ROUTE_METHOD_INVALID).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
76
|
+
expect(errorCodes.FST_ERR_ROUTE_METHOD_ALREADY_SUPPORTED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
76
77
|
expect(errorCodes.FST_ERR_ROUTE_METHOD_NOT_SUPPORTED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
77
78
|
expect(errorCodes.FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
78
79
|
expect(errorCodes.FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
@@ -81,7 +82,7 @@ expect(errorCodes.FST_ERR_ROUTE_MISSING_CONTENT_TYPE).type.toBeAssignableTo<Fast
|
|
|
81
82
|
expect(errorCodes.FST_ERR_ROUTE_MISSING_CONTENT).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
82
83
|
expect(errorCodes.FST_ERR_REOPENED_CLOSE_SERVER).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
83
84
|
expect(errorCodes.FST_ERR_REOPENED_SERVER).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
84
|
-
expect(errorCodes.
|
|
85
|
+
expect(errorCodes.FST_ERR_INSTANCE_ALREADY_STARTED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
85
86
|
expect(errorCodes.FST_ERR_PLUGIN_VERSION_MISMATCH).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
86
87
|
expect(errorCodes.FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
87
88
|
expect(errorCodes.FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER).type.toBeAssignableTo<FastifyErrorConstructor>()
|