Nightshift-Task: perf-regression Nightshift-Ref: https://github.com/marcus/nightshift
22 lines
455 B
JavaScript
22 lines
455 B
JavaScript
'use strict';
|
|
|
|
const SLOW_THRESHOLD_MS = 200;
|
|
|
|
function timingMiddleware(req, res, next) {
|
|
const start = Date.now();
|
|
|
|
res.on('finish', () => {
|
|
const duration = Date.now() - start;
|
|
const msg = `${req.method} ${req.path} ${res.statusCode} ${duration}ms`;
|
|
if (duration >= SLOW_THRESHOLD_MS) {
|
|
console.warn(`[SLOW] ${msg}`);
|
|
} else {
|
|
console.log(`[timing] ${msg}`);
|
|
}
|
|
});
|
|
|
|
next();
|
|
}
|
|
|
|
module.exports = timingMiddleware;
|