Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想禁用我之前在 app.js 中设置的特定中间件,例如:
app.use(express.bodyParser());
然后我想删除特定路线的bodyParser()例如:
app.post("/posts/add", Post.addPost);
谢谢
您可以编写一个函数来检测条件,如下所示:
function maybe(fn) { return function(req, res, next) { if (req.path === '/posts/add' && req.method === 'POST') { next(); } else { fn(req, res, next); } } }
然后修改app.use语句:
app.use(maybe(express.bodyParser()));