小编Ash*_*dav的帖子

如何使用Express从不同中间件中的响应对象获取数据

可能是这个愚蠢的问题.. :)可以帮助我从响应对象中获取数据。基本上我想使用Express中的其他中间件来验证我的响应数据

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.use('/', function(req, res, next){
    console.log('entry point');
    res.json({name:"somename",age: 29});
    next()
});

var middleware = function (req, res, next) {

console.log('LOGGED');

res.end = function (req, res , next) {
    var data = res.data;
    //do some validation logic here
    next()
}};
app.use(middleware);

var port = process.env.PORT || 10010;
app.listen(port);
Run Code Online (Sandbox Code Playgroud)

node.js express swagger swagger-ui

5
推荐指数
1
解决办法
1213
查看次数

标签 统计

express ×1

node.js ×1

swagger ×1

swagger-ui ×1