【发布时间】:2019-05-24 07:38:33
【问题描述】:
我们可以在将bodyparser作为中间件注入后禁用或覆盖它来表达应用程序吗?
在一个文件中(不可编辑,由框架完成) app.use(bodyParser.json()); 导出应用程序;
在其他文件中,我正在导入应用程序,在这里我想为其中一条路线禁用 bodyParser。有什么办法可以做到吗?
【问题讨论】:
标签: node.js express middleware body-parser
我们可以在将bodyparser作为中间件注入后禁用或覆盖它来表达应用程序吗?
在一个文件中(不可编辑,由框架完成) app.use(bodyParser.json()); 导出应用程序;
在其他文件中,我正在导入应用程序,在这里我想为其中一条路线禁用 bodyParser。有什么办法可以做到吗?
【问题讨论】:
标签: node.js express middleware body-parser
// export file
// ...
app.use((req, res, next) => {
// check if the path need body parser or not
if (BlackList.includes(req.path)) {
bodyParser.json()
}
next()
});
// ...
// import file
// ...
// some router
BlackList.push('anyway')
app.get('/anyway', function (req, res, next) {
// your code...
})
// ...
【讨论】: