From ef3999219d804a47e0d9498376558e034c3b4480 Mon Sep 17 00:00:00 2001 From: Kei <37646189+kei-ichi@users.noreply.github.com> Date: Sat, 21 Sep 2024 21:27:18 +0900 Subject: [PATCH] chore: Add named hooks for improved visibility and debugging (#261) This commit introduces named hooks in place of anonymous functions for the Fastify Helmet plugin. The changes include: 1. Renamed the first onRequest hook to 'helmetConfigureReply' 2. Renamed the second onRequest hook to 'helmetApplyHeaders' These named hooks provide better visibility when inspecting routes and improve the debugging experience. This change aligns the plugin with other Fastify plugins like @fastify/cors that use named hooks. The functionality remains unchanged; this is purely a developer experience improvement. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ce99e5d..1053c6b 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,7 @@ async function fastifyHelmet (fastify, options) { } }) - fastify.addHook('onRequest', async (request, reply) => { + fastify.addHook('onRequest', async function helmetConfigureReply (request, reply) { /* c8 ignore next */ const { helmet: routeOptions } = request.routeOptions?.config || request.routeConfig @@ -50,7 +50,7 @@ async function fastifyHelmet (fastify, options) { return replyDecorators(request, reply, globalConfiguration, enableCSPNonces) }) - fastify.addHook('onRequest', (request, reply, next) => { + fastify.addHook('onRequest', function helmetApplyHeaders (request, reply, next) { /* c8 ignore next */ const { helmet: routeOptions } = request.routeOptions?.config || request.routeConfig