mongodb - koa怎样在两个中间件之间传值?
巴扎黑
巴扎黑 2017-05-02 09:24:15
0
2
474

两个中间件之间如何传值呢

test.post('/', koaBody, function* (next) {
    var body = this.request.body;
    console.log(body);
    yield body;
    yield next;
})
app.use(function* (next) {

  this.body="sucessful";
  console.log("中间件2");
  yield this.mongo.db('app_info').collection('platform').insert({"xiaoming":"xiaoming1"});
  this.body=  this.mongo.db('app_info').collection('platform').findOne();
});

如上,我想把第一个中间件的post获取的body,传入第二个中间件中,然后由第二个中间件存入monodb。请问我应该如何获取?

巴扎黑
巴扎黑

reply all(2)
为情所困

全局变量传值

左手右手慢动作

需要先挂到ctx上,然后在下个中间件中拿到!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!