I want to disable a specific middleware, which I've set up previously in the app.js, for example:
app.use(express.bodyParser());
And then I want to remove that bodyParser() for a specific route for instance:
app.post("/posts/add", Post.addPost);
Thank you
You could write a function to detect a condition, like this:
function maybe(fn) {
return function(req, res, next) {
if (req.path === '/posts/add' && req.method === 'POST') {
next();
} else {
fn(req, res, next);
}
}
}
And then modify the app.use statement:
app.use(maybe(express.bodyParser()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With