add debugging example

This commit is contained in:
TJ Holowaychuk 2013-12-22 08:46:57 -08:00
parent 85849d0ad1
commit 6cec3c63db

37
debugging/index.js Normal file
View File

@ -0,0 +1,37 @@
/**
* Module dependencies.
*/
var koa = require('koa');
var app = koa();
// to enable debugging output per middleware
// run with the following environment variable:
// $ DEBUG=koa-compose node --harmony debugging
// note how the function names are used
// in the debug output.
app.use(function *json(next){
yield next;
this.body = { message: this.body };
});
app.use(function *reverse(next){
yield next;
this.set('X-Bar', 'baz');
this.body = this.body.split('').reverse().join('');
});
app.use(function *uppercase(next){
yield next;
this.set('X-Foo', 'bar');
this.body = this.body.toUpperCase();
});
app.use(function *response(next){
this.body = 'Hello World'
});
app.listen(3000);