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
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
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...