fastify 5.12.0 → 6.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/build/build-validation.js +20 -34
- package/docs/Guides/Getting-Started.md +2 -2
- package/docs/Reference/Errors.md +5 -3
- package/docs/Reference/Hooks.md +0 -4
- package/docs/Reference/LTS.md +6 -5
- 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/errors.js +9 -3
- package/lib/log-controller.js +2 -4
- package/lib/logger-factory.js +1 -1
- package/lib/route.js +4 -9
- package/lib/server.js +2 -3
- package/lib/warnings.js +2 -46
- package/package.json +2 -2
- 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/custom-querystring-parser.test.js +0 -16
- 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/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 +1 -16
- package/types/plugin.d.ts +0 -9
- package/types/request.d.ts +0 -4
- package/lib/promise.js +0 -23
- package/test/internals/promise.test.js +0 -63
|
@@ -277,6 +277,19 @@ test('defaultErrorLog should log error for 5xx errors', t => {
|
|
|
277
277
|
logController.defaultErrorLog(err, request, reply)
|
|
278
278
|
})
|
|
279
279
|
|
|
280
|
+
test('routeNotFound should not log when logging is disabled', t => {
|
|
281
|
+
t.plan(1)
|
|
282
|
+
const logController = new LogController({ disableRequestLogging: request => request.skipLogging })
|
|
283
|
+
const request = {
|
|
284
|
+
skipLogging: true,
|
|
285
|
+
log: {
|
|
286
|
+
info: () => { t.assert.fail('info should not be called') }
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
logController.routeNotFound(request, {})
|
|
290
|
+
t.assert.ok(true, 'logger was not called')
|
|
291
|
+
})
|
|
292
|
+
|
|
280
293
|
test('writeHeadError should not log when logging is disabled (boolean)', t => {
|
|
281
294
|
t.plan(1)
|
|
282
295
|
const logController = new LogController({ disableRequestLogging: true })
|
|
@@ -369,7 +382,7 @@ test('createLogController should use LogController instance directly', t => {
|
|
|
369
382
|
|
|
370
383
|
test('createLogController should create default when no instance provided', t => {
|
|
371
384
|
t.plan(2)
|
|
372
|
-
const dispatcher = createLogController({
|
|
385
|
+
const dispatcher = createLogController({})
|
|
373
386
|
t.assert.ok(dispatcher instanceof LogController)
|
|
374
387
|
t.assert.strictEqual(dispatcher.requestIdLogLabel, 'reqId')
|
|
375
388
|
})
|
|
@@ -377,20 +390,20 @@ test('createLogController should create default when no instance provided', t =>
|
|
|
377
390
|
test('createLogController should throw on invalid type', t => {
|
|
378
391
|
t.plan(1)
|
|
379
392
|
t.assert.throws(() => {
|
|
380
|
-
createLogController({
|
|
393
|
+
createLogController({ logController: 'bad' })
|
|
381
394
|
}, { code: 'FST_ERR_LOG_INVALID_LOG_CONTROLLER' })
|
|
382
395
|
})
|
|
383
396
|
|
|
384
397
|
test('createLogController should throw when plain object is provided', t => {
|
|
385
398
|
t.plan(1)
|
|
386
399
|
t.assert.throws(() => {
|
|
387
|
-
createLogController({
|
|
400
|
+
createLogController({ logController: { incomingRequest: () => { } } })
|
|
388
401
|
}, { code: 'FST_ERR_LOG_INVALID_LOG_CONTROLLER' })
|
|
389
402
|
})
|
|
390
403
|
|
|
391
404
|
test('createLogController should accept null', t => {
|
|
392
405
|
t.plan(1)
|
|
393
|
-
const logController = createLogController({
|
|
406
|
+
const logController = createLogController({ logController: null })
|
|
394
407
|
t.assert.ok(logController)
|
|
395
408
|
})
|
|
396
409
|
|
|
@@ -1700,7 +1700,7 @@ test('cannot set the replySerializer when the server is running', (t, done) => {
|
|
|
1700
1700
|
fastify.setReplySerializer(() => { })
|
|
1701
1701
|
t.assert.fail('this serializer should not be setup')
|
|
1702
1702
|
} catch (e) {
|
|
1703
|
-
t.assert.strictEqual(e.code, '
|
|
1703
|
+
t.assert.strictEqual(e.code, 'FST_ERR_INSTANCE_ALREADY_STARTED')
|
|
1704
1704
|
} finally {
|
|
1705
1705
|
done()
|
|
1706
1706
|
}
|
|
@@ -40,9 +40,7 @@ test('Regular request', t => {
|
|
|
40
40
|
server: {
|
|
41
41
|
[kReply]: {},
|
|
42
42
|
[kRequest]: Request,
|
|
43
|
-
[kOptions]: {
|
|
44
|
-
requestIdLogLabel: 'reqId'
|
|
45
|
-
},
|
|
43
|
+
[kOptions]: {},
|
|
46
44
|
server: {}
|
|
47
45
|
}
|
|
48
46
|
})
|
|
@@ -94,9 +92,7 @@ test('Request with undefined config', t => {
|
|
|
94
92
|
server: {
|
|
95
93
|
[kReply]: {},
|
|
96
94
|
[kRequest]: Request,
|
|
97
|
-
[kOptions]: {
|
|
98
|
-
requestIdLogLabel: 'reqId'
|
|
99
|
-
},
|
|
95
|
+
[kOptions]: {},
|
|
100
96
|
server: {}
|
|
101
97
|
}
|
|
102
98
|
})
|
|
@@ -155,9 +151,7 @@ test('Regular request - hostname from authority', t => {
|
|
|
155
151
|
server: {
|
|
156
152
|
[kReply]: {},
|
|
157
153
|
[kRequest]: Request,
|
|
158
|
-
[kOptions]: {
|
|
159
|
-
requestIdLogLabel: 'reqId'
|
|
160
|
-
},
|
|
154
|
+
[kOptions]: {},
|
|
161
155
|
server: {}
|
|
162
156
|
}
|
|
163
157
|
})
|
|
@@ -198,9 +192,7 @@ test('Regular request - host header has precedence over authority', t => {
|
|
|
198
192
|
server: {
|
|
199
193
|
[kReply]: {},
|
|
200
194
|
[kRequest]: Request,
|
|
201
|
-
[kOptions]: {
|
|
202
|
-
requestIdLogLabel: 'reqId'
|
|
203
|
-
},
|
|
195
|
+
[kOptions]: {},
|
|
204
196
|
server: {}
|
|
205
197
|
}
|
|
206
198
|
})
|
|
@@ -240,9 +232,7 @@ test('Request with trust proxy', t => {
|
|
|
240
232
|
server: {
|
|
241
233
|
[kReply]: {},
|
|
242
234
|
[kRequest]: Request,
|
|
243
|
-
[kOptions]: {
|
|
244
|
-
requestIdLogLabel: 'reqId'
|
|
245
|
-
}
|
|
235
|
+
[kOptions]: {}
|
|
246
236
|
}
|
|
247
237
|
})
|
|
248
238
|
|
|
@@ -317,9 +307,7 @@ test('Request with trust proxy - no x-forwarded-host header', t => {
|
|
|
317
307
|
server: {
|
|
318
308
|
[kReply]: {},
|
|
319
309
|
[kRequest]: Request,
|
|
320
|
-
[kOptions]: {
|
|
321
|
-
requestIdLogLabel: 'reqId'
|
|
322
|
-
},
|
|
310
|
+
[kOptions]: {},
|
|
323
311
|
server: {}
|
|
324
312
|
}
|
|
325
313
|
})
|
|
@@ -360,9 +348,7 @@ test('Request with trust proxy - no x-forwarded-host header and fallback to auth
|
|
|
360
348
|
server: {
|
|
361
349
|
[kReply]: {},
|
|
362
350
|
[kRequest]: Request,
|
|
363
|
-
[kOptions]: {
|
|
364
|
-
requestIdLogLabel: 'reqId'
|
|
365
|
-
},
|
|
351
|
+
[kOptions]: {},
|
|
366
352
|
server: {}
|
|
367
353
|
}
|
|
368
354
|
})
|
|
@@ -463,9 +449,7 @@ test('Request with undefined socket', t => {
|
|
|
463
449
|
server: {
|
|
464
450
|
[kReply]: {},
|
|
465
451
|
[kRequest]: Request,
|
|
466
|
-
[kOptions]: {
|
|
467
|
-
requestIdLogLabel: 'reqId'
|
|
468
|
-
},
|
|
452
|
+
[kOptions]: {},
|
|
469
453
|
server: {}
|
|
470
454
|
}
|
|
471
455
|
})
|
|
@@ -9,7 +9,7 @@ const pino = require('pino')
|
|
|
9
9
|
const Fastify = require('../../fastify')
|
|
10
10
|
const { LogController } = require('../../lib/log-controller')
|
|
11
11
|
const helper = require('../helper')
|
|
12
|
-
const {
|
|
12
|
+
const { on } = stream
|
|
13
13
|
const { request } = require('./logger-test-utils')
|
|
14
14
|
const { partialDeepStrictEqual } = require('../helper')
|
|
15
15
|
|
|
@@ -17,7 +17,7 @@ t.test('logging', { timeout: 60000 }, async (t) => {
|
|
|
17
17
|
let localhost
|
|
18
18
|
let localhostForURL
|
|
19
19
|
|
|
20
|
-
t.plan(
|
|
20
|
+
t.plan(11)
|
|
21
21
|
|
|
22
22
|
t.before(async function () {
|
|
23
23
|
[localhost, localhostForURL] = await helper.getLoopbackHost()
|
|
@@ -289,92 +289,6 @@ t.test('logging', { timeout: 60000 }, async (t) => {
|
|
|
289
289
|
}
|
|
290
290
|
})
|
|
291
291
|
|
|
292
|
-
await t.test('should not log incoming request and outgoing response when disabled', async (t) => {
|
|
293
|
-
t.plan(1)
|
|
294
|
-
const stream = split(JSON.parse)
|
|
295
|
-
const fastify = Fastify({ disableRequestLogging: true, logger: { level: 'info', stream } })
|
|
296
|
-
t.after(() => fastify.close())
|
|
297
|
-
|
|
298
|
-
fastify.get('/500', (req, reply) => {
|
|
299
|
-
reply.code(500).send(Error('500 error'))
|
|
300
|
-
})
|
|
301
|
-
|
|
302
|
-
await fastify.ready()
|
|
303
|
-
|
|
304
|
-
await fastify.inject({ method: 'GET', url: '/500' })
|
|
305
|
-
|
|
306
|
-
// no more readable data
|
|
307
|
-
t.assert.strictEqual(stream.readableLength, 0)
|
|
308
|
-
})
|
|
309
|
-
|
|
310
|
-
await t.test('should not log incoming request, outgoing response and route not found for 404 onBadUrl when disabled', async (t) => {
|
|
311
|
-
t.plan(1)
|
|
312
|
-
const stream = split(JSON.parse)
|
|
313
|
-
const fastify = Fastify({ disableRequestLogging: true, logger: { level: 'info', stream } })
|
|
314
|
-
t.after(() => fastify.close())
|
|
315
|
-
|
|
316
|
-
await fastify.ready()
|
|
317
|
-
|
|
318
|
-
await fastify.inject({ method: 'GET', url: '/%c0' })
|
|
319
|
-
|
|
320
|
-
// no more readable data
|
|
321
|
-
t.assert.strictEqual(stream.readableLength, 0)
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
await t.test('should not log incoming request, outgoing response and route not found for 414 onMaxParamLength when disabled', async (t) => {
|
|
325
|
-
t.plan(1)
|
|
326
|
-
const stream = split(JSON.parse)
|
|
327
|
-
const fastify = Fastify({ disableRequestLogging: true, logger: { level: 'info', stream } })
|
|
328
|
-
t.after(() => fastify.close())
|
|
329
|
-
|
|
330
|
-
await fastify.ready()
|
|
331
|
-
|
|
332
|
-
await fastify.inject({
|
|
333
|
-
method: 'GET',
|
|
334
|
-
url: `/${'1234567890'.repeat(12)}`
|
|
335
|
-
})
|
|
336
|
-
|
|
337
|
-
// no more readable data
|
|
338
|
-
t.assert.strictEqual(stream.readableLength, 0)
|
|
339
|
-
})
|
|
340
|
-
|
|
341
|
-
await t.test('should log incoming request and outgoing response based on disableRequestLogging function', async (t) => {
|
|
342
|
-
const lines = [
|
|
343
|
-
'incoming request',
|
|
344
|
-
'request completed'
|
|
345
|
-
]
|
|
346
|
-
t.plan(lines.length)
|
|
347
|
-
|
|
348
|
-
const stream = split(JSON.parse)
|
|
349
|
-
const loggerInstance = pino(stream)
|
|
350
|
-
|
|
351
|
-
const fastify = Fastify({
|
|
352
|
-
disableRequestLogging: (request) => {
|
|
353
|
-
return request.url !== '/not-logged'
|
|
354
|
-
},
|
|
355
|
-
loggerInstance
|
|
356
|
-
})
|
|
357
|
-
t.after(() => fastify.close())
|
|
358
|
-
|
|
359
|
-
fastify.get('/logged', (req, reply) => {
|
|
360
|
-
return reply.code(200).send({})
|
|
361
|
-
})
|
|
362
|
-
|
|
363
|
-
fastify.get('/not-logged', (req, reply) => {
|
|
364
|
-
return reply.code(200).send({})
|
|
365
|
-
})
|
|
366
|
-
|
|
367
|
-
await fastify.ready()
|
|
368
|
-
|
|
369
|
-
await fastify.inject({ method: 'GET', url: '/not-logged' })
|
|
370
|
-
await fastify.inject({ method: 'GET', url: '/logged' })
|
|
371
|
-
|
|
372
|
-
for await (const [line] of on(stream, 'data')) {
|
|
373
|
-
t.assert.strictEqual(line.msg, lines.shift())
|
|
374
|
-
if (lines.length === 0) break
|
|
375
|
-
}
|
|
376
|
-
})
|
|
377
|
-
|
|
378
292
|
await t.test('defaults to info level', async (t) => {
|
|
379
293
|
const lines = [
|
|
380
294
|
{ req: { method: 'GET' }, msg: 'incoming request' },
|
|
@@ -480,37 +394,4 @@ t.test('logging', { timeout: 60000 }, async (t) => {
|
|
|
480
394
|
if (lines.length === 0) break
|
|
481
395
|
}
|
|
482
396
|
})
|
|
483
|
-
|
|
484
|
-
await t.test('should not log the error if request logging is disabled', async (t) => {
|
|
485
|
-
t.plan(4)
|
|
486
|
-
|
|
487
|
-
const stream = split(JSON.parse)
|
|
488
|
-
const fastify = Fastify({
|
|
489
|
-
logger: {
|
|
490
|
-
stream,
|
|
491
|
-
level: 'info'
|
|
492
|
-
},
|
|
493
|
-
disableRequestLogging: true
|
|
494
|
-
})
|
|
495
|
-
t.after(() => fastify.close())
|
|
496
|
-
|
|
497
|
-
fastify.get('/error', function (req, reply) {
|
|
498
|
-
t.assert.ok(req.log)
|
|
499
|
-
reply.send(new Error('a generic error'))
|
|
500
|
-
})
|
|
501
|
-
|
|
502
|
-
await fastify.ready()
|
|
503
|
-
await fastify.listen({ port: 0, host: localhost })
|
|
504
|
-
|
|
505
|
-
await request(`http://${localhostForURL}:` + fastify.server.address().port + '/error')
|
|
506
|
-
|
|
507
|
-
{
|
|
508
|
-
const [line] = await once(stream, 'data')
|
|
509
|
-
t.assert.ok(typeof line.msg === 'string')
|
|
510
|
-
t.assert.ok(line.msg.startsWith('Server listening at'), 'message is set')
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
// no more readable data
|
|
514
|
-
t.assert.strictEqual(stream.readableLength, 0)
|
|
515
|
-
})
|
|
516
397
|
})
|
|
@@ -14,7 +14,7 @@ const { partialDeepStrictEqual } = require('../helper')
|
|
|
14
14
|
t.test('request', { timeout: 60000 }, async (t) => {
|
|
15
15
|
let localhost
|
|
16
16
|
|
|
17
|
-
t.plan(
|
|
17
|
+
t.plan(6)
|
|
18
18
|
t.before(async function () {
|
|
19
19
|
[localhost] = await helper.getLoopbackHost()
|
|
20
20
|
})
|
|
@@ -180,41 +180,6 @@ t.test('request', { timeout: 60000 }, async (t) => {
|
|
|
180
180
|
}
|
|
181
181
|
})
|
|
182
182
|
|
|
183
|
-
await t.test('The request id log label can be changed', async (t) => {
|
|
184
|
-
const REQUEST_ID = '42'
|
|
185
|
-
const matches = [
|
|
186
|
-
{ traceId: REQUEST_ID, msg: 'incoming request' },
|
|
187
|
-
{ traceId: REQUEST_ID, msg: 'some log message' },
|
|
188
|
-
{ traceId: REQUEST_ID, msg: 'request completed' }
|
|
189
|
-
]
|
|
190
|
-
t.plan(matches.length + 2)
|
|
191
|
-
|
|
192
|
-
const stream = split(JSON.parse)
|
|
193
|
-
const fastify = Fastify({
|
|
194
|
-
logger: { stream, level: 'info' },
|
|
195
|
-
requestIdHeader: 'my-custom-request-id',
|
|
196
|
-
requestIdLogLabel: 'traceId'
|
|
197
|
-
})
|
|
198
|
-
t.after(() => fastify.close())
|
|
199
|
-
|
|
200
|
-
fastify.get('/one', (req, reply) => {
|
|
201
|
-
t.assert.strictEqual(req.id, REQUEST_ID)
|
|
202
|
-
req.log.info('some log message')
|
|
203
|
-
reply.send({ id: req.id })
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
{
|
|
207
|
-
const response = await fastify.inject({ method: 'GET', url: '/one', headers: { 'my-custom-request-id': REQUEST_ID } })
|
|
208
|
-
const body = await response.json()
|
|
209
|
-
t.assert.strictEqual(body.id, REQUEST_ID)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
for await (const [line] of on(stream, 'data')) {
|
|
213
|
-
t.assert.ok(partialDeepStrictEqual(line, matches.shift()))
|
|
214
|
-
if (matches.length === 0) break
|
|
215
|
-
}
|
|
216
|
-
})
|
|
217
|
-
|
|
218
183
|
await t.test('should redact the authorization header if so specified', async (t) => {
|
|
219
184
|
const stream = split(JSON.parse)
|
|
220
185
|
const fastify = Fastify({
|
|
@@ -459,7 +459,9 @@ test('prefix "/prefix/" does not match "/prefix" with a / route', (t, testDone)
|
|
|
459
459
|
test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true', (t, testDone) => {
|
|
460
460
|
t.plan(4)
|
|
461
461
|
const fastify = Fastify({
|
|
462
|
-
|
|
462
|
+
routerOptions: {
|
|
463
|
+
ignoreTrailingSlash: true
|
|
464
|
+
}
|
|
463
465
|
})
|
|
464
466
|
|
|
465
467
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -493,7 +495,9 @@ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: tr
|
|
|
493
495
|
test('matches both /prefix and /prefix/ with a / route - ignoreDuplicateSlashes: true', (t, testDone) => {
|
|
494
496
|
t.plan(4)
|
|
495
497
|
const fastify = Fastify({
|
|
496
|
-
|
|
498
|
+
routerOptions: {
|
|
499
|
+
ignoreDuplicateSlashes: true
|
|
500
|
+
}
|
|
497
501
|
})
|
|
498
502
|
|
|
499
503
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -527,7 +531,9 @@ test('matches both /prefix and /prefix/ with a / route - ignoreDuplicateSlashes:
|
|
|
527
531
|
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreTrailingSlash: false', (t, testDone) => {
|
|
528
532
|
t.plan(4)
|
|
529
533
|
const fastify = Fastify({
|
|
530
|
-
|
|
534
|
+
routerOptions: {
|
|
535
|
+
ignoreTrailingSlash: false
|
|
536
|
+
}
|
|
531
537
|
})
|
|
532
538
|
|
|
533
539
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -566,7 +572,9 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
|
|
|
566
572
|
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: false', (t, testDone) => {
|
|
567
573
|
t.plan(4)
|
|
568
574
|
const fastify = Fastify({
|
|
569
|
-
|
|
575
|
+
routerOptions: {
|
|
576
|
+
ignoreDuplicateSlashes: false
|
|
577
|
+
}
|
|
570
578
|
})
|
|
571
579
|
|
|
572
580
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -605,8 +613,10 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
|
|
|
605
613
|
test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true, ignoreDuplicateSlashes: true', (t, testDone) => {
|
|
606
614
|
t.plan(4)
|
|
607
615
|
const fastify = Fastify({
|
|
608
|
-
|
|
609
|
-
|
|
616
|
+
routerOptions: {
|
|
617
|
+
ignoreTrailingSlash: true,
|
|
618
|
+
ignoreDuplicateSlashes: true
|
|
619
|
+
}
|
|
610
620
|
})
|
|
611
621
|
|
|
612
622
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -640,8 +650,10 @@ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: tr
|
|
|
640
650
|
test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true, ignoreDuplicateSlashes: false', (t, testDone) => {
|
|
641
651
|
t.plan(4)
|
|
642
652
|
const fastify = Fastify({
|
|
643
|
-
|
|
644
|
-
|
|
653
|
+
routerOptions: {
|
|
654
|
+
ignoreTrailingSlash: true,
|
|
655
|
+
ignoreDuplicateSlashes: false
|
|
656
|
+
}
|
|
645
657
|
})
|
|
646
658
|
|
|
647
659
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -675,7 +687,9 @@ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: tr
|
|
|
675
687
|
test('returns 404 status code with /prefix/ and / route - prefixTrailingSlash: "both" (default), ignoreTrailingSlash: true', (t, testDone) => {
|
|
676
688
|
t.plan(2)
|
|
677
689
|
const fastify = Fastify({
|
|
678
|
-
|
|
690
|
+
routerOptions: {
|
|
691
|
+
ignoreTrailingSlash: true
|
|
692
|
+
}
|
|
679
693
|
})
|
|
680
694
|
|
|
681
695
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -707,7 +721,9 @@ test('returns 404 status code with /prefix/ and / route - prefixTrailingSlash: "
|
|
|
707
721
|
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: true', (t, testDone) => {
|
|
708
722
|
t.plan(2)
|
|
709
723
|
const fastify = Fastify({
|
|
710
|
-
|
|
724
|
+
routerOptions: {
|
|
725
|
+
ignoreDuplicateSlashes: true
|
|
726
|
+
}
|
|
711
727
|
})
|
|
712
728
|
|
|
713
729
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -735,8 +751,10 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
|
|
|
735
751
|
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreTrailingSlash: true, ignoreDuplicateSlashes: true', (t, testDone) => {
|
|
736
752
|
t.plan(2)
|
|
737
753
|
const fastify = Fastify({
|
|
738
|
-
|
|
739
|
-
|
|
754
|
+
routerOptions: {
|
|
755
|
+
ignoreTrailingSlash: true,
|
|
756
|
+
ignoreDuplicateSlashes: true
|
|
757
|
+
}
|
|
740
758
|
})
|
|
741
759
|
|
|
742
760
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -764,8 +782,10 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
|
|
|
764
782
|
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: true', (t, testDone) => {
|
|
765
783
|
t.plan(2)
|
|
766
784
|
const fastify = Fastify({
|
|
767
|
-
|
|
768
|
-
|
|
785
|
+
routerOptions: {
|
|
786
|
+
ignoreTrailingSlash: true,
|
|
787
|
+
ignoreDuplicateSlashes: true
|
|
788
|
+
}
|
|
769
789
|
})
|
|
770
790
|
|
|
771
791
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -793,7 +813,9 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
|
|
|
793
813
|
test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ignoreTrailingSlash: false', (t, testDone) => {
|
|
794
814
|
t.plan(4)
|
|
795
815
|
const fastify = Fastify({
|
|
796
|
-
|
|
816
|
+
routerOptions: {
|
|
817
|
+
ignoreTrailingSlash: false
|
|
818
|
+
}
|
|
797
819
|
})
|
|
798
820
|
|
|
799
821
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -832,7 +854,9 @@ test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ig
|
|
|
832
854
|
test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ignoreDuplicateSlashes: false', (t, testDone) => {
|
|
833
855
|
t.plan(4)
|
|
834
856
|
const fastify = Fastify({
|
|
835
|
-
|
|
857
|
+
routerOptions: {
|
|
858
|
+
ignoreDuplicateSlashes: false
|
|
859
|
+
}
|
|
836
860
|
})
|
|
837
861
|
|
|
838
862
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -871,7 +895,9 @@ test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ig
|
|
|
871
895
|
test('matches only /prefix/ with a / route - prefixTrailingSlash: "slash", ignoreTrailingSlash: false', (t, testDone) => {
|
|
872
896
|
t.plan(4)
|
|
873
897
|
const fastify = Fastify({
|
|
874
|
-
|
|
898
|
+
routerOptions: {
|
|
899
|
+
ignoreTrailingSlash: false
|
|
900
|
+
}
|
|
875
901
|
})
|
|
876
902
|
|
|
877
903
|
fastify.register(function (fastify, opts, done) {
|
|
@@ -910,7 +936,9 @@ test('matches only /prefix/ with a / route - prefixTrailingSlash: "slash", igno
|
|
|
910
936
|
test('calls onRoute only once when prefixing', async t => {
|
|
911
937
|
t.plan(1)
|
|
912
938
|
const fastify = Fastify({
|
|
913
|
-
|
|
939
|
+
routerOptions: {
|
|
940
|
+
ignoreTrailingSlash: false
|
|
941
|
+
},
|
|
914
942
|
exposeHeadRoutes: false
|
|
915
943
|
})
|
|
916
944
|
|
package/test/route.1.test.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
4
|
const Fastify = require('..')
|
|
5
5
|
const {
|
|
6
|
-
|
|
6
|
+
FST_ERR_INSTANCE_ALREADY_STARTED,
|
|
7
7
|
FST_ERR_ROUTE_METHOD_INVALID
|
|
8
8
|
} = require('../lib/errors')
|
|
9
9
|
const { getServerUrl } = require('./helper')
|
|
@@ -230,7 +230,7 @@ test('route', async t => {
|
|
|
230
230
|
handler: function (req, reply) {
|
|
231
231
|
reply.send({ hello: 'world' })
|
|
232
232
|
}
|
|
233
|
-
}), new
|
|
233
|
+
}), new FST_ERR_INSTANCE_ALREADY_STARTED('Cannot add route!'))
|
|
234
234
|
})
|
|
235
235
|
})
|
|
236
236
|
|