From 5bd7eb6fdbdc347ac1a7107b80f9539e258b59a7 Mon Sep 17 00:00:00 2001 From: kei-ichi Date: Sat, 21 Sep 2024 18:51:13 +0900 Subject: [PATCH] chore: Add named hooks for improved visibility and debugging 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