问题描述
两个中间件之间如何传值呢
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。请问我应该如何获取?
问题解答
回答1:全局变量传值
回答2:需要先挂到ctx上,然后在下个中间件中拿到!

