Skip to content

Commit

Permalink
chore: Add named hooks for improved visibility and debugging (#261)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kei-ichi authored Sep 21, 2024
1 parent 188d984 commit ef39992
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit ef39992

Please sign in to comment.