Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: named hook handlers #152

Merged
merged 1 commit into from
Sep 25, 2024
Merged

chore: named hook handlers #152

merged 1 commit into from
Sep 25, 2024

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Sep 22, 2024

@Eomm

is this the naming you suggest in your book?

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I suggest to use named function because it improves the stack trace and debug tools (such as fastify-overview)

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Sep 22, 2024

i mean more like, what is the naming convention?

i used caching as prefix fo the hook handlers and a name describing the functionality-

@@ -70,7 +70,7 @@ function fastifyCaching (instance, options, next) {
value += `, s-maxage=${_options.serverExpiresIn}`
}

instance.addHook('onRequest', (req, res, next) => {
instance.addHook('onRequest', function cachingSetCacheControlHeader (req, res, next) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really the only change needed in this PR. The other names are fine; the fact that they are named is enough. And we don't need names in the tests. The names provide information when reviewing stack traces, stepping through with a debugger, and reviewing observability data.

@Uzlopak Uzlopak merged commit 742aec4 into master Sep 25, 2024
13 checks passed
@Uzlopak Uzlopak deleted the chore-named-hook-fn branch September 25, 2024 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants