How to use different middlewares for each method on the same handler
Closed this issue · 1 comments
RadoslavMarinov commented
In Express we can do it by adding the middleware into the method like so:
app.get('/user/:userId', getMiddleware, (req,res)=>....
app.delete('/user/:userId', deleteMiddleware, (req,res)=>....
How to do the trick in next-connect?
If I apply middleware to the GET it will always trigger for the DELETE method as well.
I want really separate independent middleware for the two methods
RadoslavMarinov commented
My mistake it is possible actually. This works
handler.get(...validateGetReq(), async(req:NextApiRequest, res:NextApiResponse)=>{
handler.delete(...validateDeleteReq(),async(req:NextApiRequest, res:NextApiResponse)=>{