add names to simple example middleware

This commit is contained in:
TJ Holowaychuk 2013-08-28 21:05:35 -07:00
parent 7db6987ccc
commit 3eafcdd85a

View file

@ -6,7 +6,7 @@ var app = koa();
// x-response-time
app.use(function(next){
return function *(){
return function *responseTime(){
var start = new Date;
yield next;
var ms = new Date - start;
@ -17,7 +17,7 @@ app.use(function(next){
// logger
app.use(function(next){
return function *(){
return function *logger(){
var start = new Date;
yield next;
var ms = new Date - start;
@ -28,7 +28,7 @@ app.use(function(next){
// content-length
app.use(function(next){
return function *(){
return function *contentLength(){
yield next;
if (!this.body) return;
this.set('Content-Length', Buffer.byteLength(this.body));
@ -38,7 +38,7 @@ app.use(function(next){
// custom 404 handler
app.use(function(next){
return function *(){
return function *notfound(){
yield next;
if (this.body) return;
this.status = 404;
@ -49,7 +49,7 @@ app.use(function(next){
// response
app.use(function(next){
return function *(){
return function *response(){
yield next;
if ('/' != this.url) return;
this.body = 'Hello World';