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
|
// x-response-time
|
||||||
|
|
||||||
app.use(function(next){
|
app.use(function(next){
|
||||||
return function *(){
|
return function *responseTime(){
|
||||||
var start = new Date;
|
var start = new Date;
|
||||||
yield next;
|
yield next;
|
||||||
var ms = new Date - start;
|
var ms = new Date - start;
|
||||||
|
@ -17,7 +17,7 @@ app.use(function(next){
|
||||||
// logger
|
// logger
|
||||||
|
|
||||||
app.use(function(next){
|
app.use(function(next){
|
||||||
return function *(){
|
return function *logger(){
|
||||||
var start = new Date;
|
var start = new Date;
|
||||||
yield next;
|
yield next;
|
||||||
var ms = new Date - start;
|
var ms = new Date - start;
|
||||||
|
@ -28,7 +28,7 @@ app.use(function(next){
|
||||||
// content-length
|
// content-length
|
||||||
|
|
||||||
app.use(function(next){
|
app.use(function(next){
|
||||||
return function *(){
|
return function *contentLength(){
|
||||||
yield next;
|
yield next;
|
||||||
if (!this.body) return;
|
if (!this.body) return;
|
||||||
this.set('Content-Length', Buffer.byteLength(this.body));
|
this.set('Content-Length', Buffer.byteLength(this.body));
|
||||||
|
@ -38,7 +38,7 @@ app.use(function(next){
|
||||||
// custom 404 handler
|
// custom 404 handler
|
||||||
|
|
||||||
app.use(function(next){
|
app.use(function(next){
|
||||||
return function *(){
|
return function *notfound(){
|
||||||
yield next;
|
yield next;
|
||||||
if (this.body) return;
|
if (this.body) return;
|
||||||
this.status = 404;
|
this.status = 404;
|
||||||
|
@ -49,7 +49,7 @@ app.use(function(next){
|
||||||
// response
|
// response
|
||||||
|
|
||||||
app.use(function(next){
|
app.use(function(next){
|
||||||
return function *(){
|
return function *response(){
|
||||||
yield next;
|
yield next;
|
||||||
if ('/' != this.url) return;
|
if ('/' != this.url) return;
|
||||||
this.body = 'Hello World';
|
this.body = 'Hello World';
|
||||||
|
|
Loading…
Reference in a new issue