mongodb - How to pass values ​​between two middlewares in koa?
巴扎黑
巴扎黑 2017-05-02 09:24:15
0
2
597

How to transfer values ​​between two middlewares

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();
});

As above, I want to pass the body obtained by the post of the first middleware into the second middleware, and then store it in monodb by the second middleware. How should I obtain it?

巴扎黑
巴扎黑

reply all(2)
为情所困

Transfer value to global variables

左手右手慢动作

You need to hang it on ctx first, and then get it in the next middleware!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template