From 6cec3c63db94405a67db0c0932ef66580db2fed5 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Sun, 22 Dec 2013 08:46:57 -0800 Subject: [PATCH] add debugging example --- debugging/index.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 debugging/index.js diff --git a/debugging/index.js b/debugging/index.js new file mode 100644 index 0000000..fb3b888 --- /dev/null +++ b/debugging/index.js @@ -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); \ No newline at end of file