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?
ringa_lee2017-05-02 09:26:15
You need to hang it on ctx
first, and then get it in the next middleware!