Skip to content

Commit 562332a

Browse files
fix: Only remove implicit HEAD routes. (fastify#4596)
* fix: Only remove implicit HEAD routes. * test: Added test. * Update test/route.test.js Co-authored-by: James Sumners <[email protected]> --------- Co-authored-by: James Sumners <[email protected]>
1 parent 1e9c10f commit 562332a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/route.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ function buildRouting (options) {
303303

304304
// remove the head route created by fastify
305305
if (hasHEADHandler && !context[kRouteByFastify] && headHandler.store[kRouteByFastify]) {
306-
router.off(opts.method, opts.url, { constraints })
306+
router.off('HEAD', opts.url, { constraints })
307307
}
308308

309309
try {

test/route.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,3 +1493,17 @@ test('exposeHeadRoute should not reuse the same route option', async t => {
14931493
}
14941494
})
14951495
})
1496+
1497+
test('using fastify.all when a catchall is defined does not degrade performance', { timeout: 5000 }, async t => {
1498+
t.plan(1)
1499+
1500+
const fastify = Fastify()
1501+
1502+
fastify.get('/*', async (_, reply) => reply.json({ ok: true }))
1503+
1504+
for (let i = 0; i < 100; i++) {
1505+
fastify.all(`/${i}`, async (_, reply) => reply.json({ ok: true }))
1506+
}
1507+
1508+
t.pass()
1509+
})

0 commit comments

Comments
 (0)