Cascading Middleware in Node 0.12 with Koa> [architect]

Ponder this panda…

$ node --harmony my-koa-app.js
listening on :3000
outbound middleware 1
outbound middleware 2
outbound middleware 3
outbound middleware 4
return middleware 4
return middleware 3
return middleware 2
return middleware 1

from…

var koa = require('koa');
var app = koa();

app.use(function *(next) {
    console.log('outbound middleware 1');
    yield next;
    console.log('return middleware 1');
});

app.use(function *(next) {
    console.log('outbound middleware 2');
    yield next;
    console.log('return middleware 2');
});

app.use(function *(next) {
    console.log('outbound middleware 3');
    yield next;
    console.log('return middleware 3');
});

app.use(function *(next) {
    console.log('outbound middleware 4');
    yield next;
    console.log('return middleware 4');
});

app.use(function *() {
    this.body = 'Final Response';
});

console.log('listening on :3000');
app.listen(3000);

 

http://koajs.com/

https://github.com/koajs/koa/wiki

Leave a Reply