-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
good first issueGood for newcomersGood for newcomers
Description
🚀 Feature Proposal
Based on a conversation in gitter today (at 00h52 AM - São Paulo - Brazil), a user of fastify reported to me that would like create a stopWatch metric for each route.
The fastest solution that I found for her is:
const calcTimeByRoute = routeName => (request, reply) => {
console.log(`[${routeName}] Elapsed: ${request.YourDecoratorTimer.elapsedTime()}`)
}
fastify.register(async (fastify, opts) => {
fastify.get('/route1', async (request, reply) => ({}))
fastify.addHook('onResponse', calcTimeByRoute('route1'))
})
fastify.register(async (fastify, opts) => {
fastify.get('/route2', async (request, reply) => ({}))
fastify.addHook('onResponse', calcTimeByRoute('route2'))
})But if we expose something like:
fastify.route({
url: '/route1',
method: 'GET',
handler: async (request, reply) => ({}),
onResponse: (request, reply) => { ... }
}What do you think? Overhead?
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomers