-
-
Save oroce/03349e92eb0f6d282d0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.use(function *responseTime(next){ | |
var start = new Date; | |
yield next; | |
var ms = new Date - start; | |
this.set('X-Response-Time', ms + 'ms'); | |
}); | |
app.use(function *logger(next){ | |
var start = new Date; | |
yield next; | |
var ms = new Date - start; | |
console.log('%s %s - %s', this.method, this.url, ms); | |
}); | |
app.use(function *response(next){ | |
yield next; | |
this.body = 'Hello Nodebp!' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express(); | |
app.use(function responseTime(req, res) { | |
var start = new Date(); | |
var end = res.end; | |
res.end = function() { | |
var ms = new Date() - start; | |
res.set('X-Response-Time', ms + 'ms'); | |
end.apply(res,arguments); | |
}; | |
req.next(); | |
}); | |
app.use(function logger(req, res) { | |
var start = new Date(); | |
var end = res.end; | |
res.end = function() { | |
var ms = new Date() - start; | |
console.log('%s %s - %s', req.method, req.url, ms); | |
end.apply(res,arguments); | |
}; | |
req.next(); | |
}); | |
app.use(function response(req, res){ | |
res.send('Hello Nodebp!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment