mirror of
https://github.com/koajs/examples.git
synced 2026-01-18 14:38:19 +00:00
add debugging example
This commit is contained in:
parent
85849d0ad1
commit
6cec3c63db
37
debugging/index.js
Normal file
37
debugging/index.js
Normal 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);
|
||||
Loading…
x
Reference in New Issue
Block a user