Skip to content

Commit

Permalink
fix: wrapped route handlers were forced to be async or return a promi…
Browse files Browse the repository at this point in the history
…se (#62)
  • Loading branch information
10xLaCroixDrinker authored Feb 6, 2024
1 parent a12cf85 commit d5f59ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async function openTelemetryPlugin (fastify, opts = {}) {

if (wrapRoutes) {
function wrapRoute (routeHandler) {
return async function (request, ...args) {
return function (request, ...args) {
const reqContext = getContext(request)
return context.with(reqContext, routeHandler.bind(this, request, ...args))
}
Expand Down
6 changes: 4 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,12 @@ test('should wrap all routes when wrapRoutes is true', async ({ equal, same, tea

await fastify.register(openTelemetryPlugin, { wrapRoutes: true })

async function testHandlerOne (request, reply) {
function testHandlerOne (request, reply) {
request.openTelemetry()
reply.headers({ one: 'ok' })
return { body: 'one' }
setTimeout(() => {
reply.send({ body: 'one' })
}, 0)
}

async function testHandlerTwo (request, reply) {
Expand Down

0 comments on commit d5f59ef

Please sign in to comment.