Skip to content

Commit

Permalink
Make hooks accessible in the same fastify context, fixes #702
Browse files Browse the repository at this point in the history
  • Loading branch information
iwaiktos committed Dec 18, 2024
1 parent 6aa0de0 commit c356143
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sdk_contrib/fastify/lib/plugin.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
// @ts-check
const fp = require('fastify-plugin').default;
const configureAWSXRaySync = require('./private/configure-aws-x-ray-sync');
const onRequestHook = require('./hooks/on-request.hook');
const onResponseHook = require('./hooks/on-response.hook');
const onErrorHook = require('./hooks/on-error.hook');

/** @type {import('fastify').FastifyPluginAsync} */
const xRayFastifyPlugin = async (fastify, opts) => {
const xRayFastifyPlugin = fp(async (fastify, opts) => {
configureAWSXRaySync(fastify, opts);

fastify.decorateRequest('segment', null);
fastify
.addHook('onRequest', onRequestHook)
.addHook('onResponse', onResponseHook)
.addHook('onError', onErrorHook);
};
});

module.exports = xRayFastifyPlugin;

Expand Down

0 comments on commit c356143

Please sign in to comment.