You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.
I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal
Add in the Hooks page that registering a global hook after adding a new endpoint, the global hook will still run
Motivation
Migrating from express to Fastify can lead to this problem:
Example code in express:
constexpress=require('express')constapp=express()constrouter=express.Router()router.post('/user/:id',function(req,res){res.send('signing up user!')})// predicate the router with a check and bail out when neededrouter.use(function(req,res,next){if(!req.headers['x-auth'])returnnext('router')next()})// other routes
Example code in fastify:
constFastify=require("fastify");constfastifyJwt=require("fastify-jwt");constfastify=Fastify({logger: false,});fastify.register(require("fastify-jwt"),{secret: "secret",});fastify.post("/signup",(req,reply)=>{consttoken=fastify.jwt.sign({userId: "kent-beck"});reply.send({ token });});fastify.addHook("onRequest",async(request,reply)=>{try{awaitrequest.jwtVerify();}catch(err){reply.send(err);}});// other routes
Doing the above code in fastify one could think that the hook only runs for requests that happen after the hook declaration
Example
No response
I can create a PR if interested...
The text was updated successfully, but these errors were encountered:
rluvaton
changed the title
Mention in the hooks page that registering a global hook after adding a new endpoin will still run
Mention in the hooks page that registering a global hook after adding a new endpoint will still run
Feb 7, 2022
Prerequisites
🚀 Feature Proposal
Add in the Hooks page that registering a global hook after adding a new endpoint, the global hook will still run
Motivation
Migrating from express to Fastify can lead to this problem:
Example code in express:
Example code in fastify:
Doing the above code in fastify one could think that the hook only runs for requests that happen after the hook declaration
Example
No response
I can create a PR if interested...
The text was updated successfully, but these errors were encountered: