In code bellow, I would like that somehow changed commented part should be able to set document's body instead of "this.body = 'test';" (it still should be Promise solution).
'use strict'
var app = require('koa')(),
router = require('koa-router')();
router.get('/', function *(next) {
this.body = 'test';
// var promise = new Promise(function(resolve, reject) {
// resolve("test");
// });
// promise.then(function(res){
// this.body = res;
// })
});
app
.use(router.routes())
app.listen(8000);
The problem is that "this" inside a Promise is not referred to "the right one".