remove the compose and cookies examples
moved to koajs/examples with tests
This commit is contained in:
parent
401559c7f7
commit
017bfef8ba
2 changed files with 0 additions and 63 deletions
|
@ -1,50 +0,0 @@
|
|||
|
||||
var compose = require('koa-compose');
|
||||
var koa = require('..');
|
||||
var app = koa();
|
||||
|
||||
// x-response-time
|
||||
|
||||
function responseTime(){
|
||||
return function *responseTime(next){
|
||||
var start = new Date;
|
||||
yield next;
|
||||
var ms = new Date - start;
|
||||
this.set('X-Response-Time', ms + 'ms');
|
||||
}
|
||||
}
|
||||
|
||||
// logger
|
||||
|
||||
function logger(){
|
||||
return function* logger(next){
|
||||
var start = new Date;
|
||||
yield next;
|
||||
var ms = new Date - start;
|
||||
console.log('%s %s - %s', this.method, this.url, ms);
|
||||
}
|
||||
}
|
||||
|
||||
// response
|
||||
|
||||
function respond() {
|
||||
return function* respond(next){
|
||||
yield next;
|
||||
if ('/' != this.url) return;
|
||||
this.body = 'Hello World';
|
||||
}
|
||||
}
|
||||
|
||||
// composed middleware
|
||||
|
||||
function all() {
|
||||
return compose([
|
||||
responseTime(),
|
||||
logger(),
|
||||
respond()
|
||||
]);
|
||||
}
|
||||
|
||||
app.use(all());
|
||||
|
||||
app.listen(3000);
|
|
@ -1,13 +0,0 @@
|
|||
|
||||
var koa = require('..');
|
||||
var app = koa();
|
||||
|
||||
app.use(function *(){
|
||||
if ('/favicon.ico' == this.path) return;
|
||||
var n = ~~this.cookies.get('view') || 1;
|
||||
this.cookies.set('view', n + 1);
|
||||
this.body = n + ' views';
|
||||
});
|
||||
|
||||
app.listen(3000);
|
||||
console.log('listening on port 3000');
|
Loading…
Reference in a new issue