add names to simple example middleware
This commit is contained in:
parent
7db6987ccc
commit
3eafcdd85a
1 changed files with 5 additions and 5 deletions
|
@ -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';
|
||||
|
|
Loading…
Reference in a new issue