I have a simple setup for koa.js with koa-route and koa-ejs.
var koa = require('koa');
var route = require('koa-route');
var add_ejs = require('koa-ejs');
var app = koa();
add_ejs(app, {…});
app.use(function *(next){
console.log( 'to do layout tweak for all requests' );
yield next;
});
app.use(route.get('/', function *(name) {
console.log( 'root action' );
yield this.render('index', {name: 'Hello' });
}));
What's the best way to pass values between those two methods?
ctx.state.thingToPassToOtherMiddlware = "Something"
and in the other middlwarevar thingToPassToOtherMiddlware = ctx.state.thingToPassToOtherMiddlware
– Fairlie