I think a simple way of doing this could be:
const middleware = (req, res, next) => {
req.param.name ? req.url = '/POST' : req.url = '/UPDATE'
next();
}
, Or you can redirect your request to other routes.
const middleware = (req, res, next) => {
req.param.name ? res.redirect('/POST') : res.redirect(/UPDATE')
next();
}
Also, you can make dynamic routes if you have many routes involved doing different things. You can check this: How to call an api from another api in expressjs?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…