Ваше промежуточное ПО (interceptor
в моем примере) может получить доступ к телу ответа после него yield next
, поэтому просто поместите свою логику после ее ввода.
var route = require('koa-route');
var app = require('koa')();
var interceptor = function*(next) {
// wait for downstream middleware/handlers to execute
// so that we can inspect the response
yield next;
// our handler has run and set the response body,
// so now we can access it
console.log('Response body:', this.body);
if (this.body === 'no promission') {
this.redirect('/somewhere');
}
};
app.use(interceptor);
app.use(route.get('/', function*() {
this.body = 'no promission';
}));
app.listen(3001, function() {
console.log('Listening on 3001...');
});
Вы не можете уточнить свой вопрос? откуда берутся эти ответы? –