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

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

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

巴扎黑
巴扎黑

모든 응답(2)
为情所困

全局变量传值

左手右手慢动作

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

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!