搜索

首页  >  问答  >  正文

mongodb - koa怎样在两个中间件之间传值?

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

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。请问我应该如何获取?

巴扎黑巴扎黑2867 天前631

全部回复(2)我来回复

  • 为情所困

    为情所困2017-05-02 09:26:15

    全局变量传值

    回复
    0
  • ringa_lee

    ringa_lee2017-05-02 09:26:15

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

    回复
    0
  • 取消回复