fix simple example
This commit is contained in:
parent
fae98c10ec
commit
0c19a060c4
1 changed files with 12 additions and 12 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue