868080
刚刚开始学习koajs,我在想把通过post传入的数据存入数据库之后再应答请求 具体代码:
function *(next) {
var _this = this;
var post = new Post({
content: this.request.body.content,
sequence: this.request.body.sequence
});
var promise = new Promise(function(resolve, reject) {
post.save(function(err, result) {
if (err) {
reject();
}else {
resolve();
};
});
});
promise.then(function() {
return _this.body = {
result: 'haha'
}
}, function() {
return _this.body = {
result: 'wuwu'
}
});
}
然后我发现我的请求返回值都是404,使用了bodyparser包,不知道和这个有没有关系