From 0c19a060c4ddf22873a40915877811d540f4c762 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Tue, 27 Aug 2013 22:42:05 -0700 Subject: [PATCH] fix simple example --- examples/simple.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/simple.js b/examples/simple.js index ba01bd3..4829f1f 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -30,30 +30,30 @@ app.use(function(next){ app.use(function(next){ return function *(){ yield next; + if (!this.body) return; this.set('Content-Length', Buffer.byteLength(this.body)); } }); +// custom 404 handler + +app.use(function(next){ + return function *(){ + yield next; + if (this.body) return; + this.status = 404; + this.body = 'Sorry! No luck'; + } +}); + // response app.use(function(next){ return function *(){ yield next; if ('/' != this.url) return; - this.status = 200; this.body = 'Hello World'; } }); -// custom 404 handler - -app.use(function(next){ - return function *(){ - yield next; - this.status = 404; - this.body = 'Sorry cannot find that!'; - console.log(this); - } -}); - app.listen(3000);