mirror of
https://github.com/Unleash/unleash.git
synced 2024-10-18 20:09:08 +02:00
240c6a77a1
feat: options are now typed - This makes it easier to know what to send to unleash.start / unleash.create - Using a Partial to instantiate the config, then melding it with defaults to get a config object with all fields set either to their defaults or to whatever is passed in. Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com> Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
23 lines
668 B
TypeScript
23 lines
668 B
TypeScript
import * as responseTime from 'response-time';
|
|
import EventEmitter from 'events';
|
|
import { REQUEST_TIME } from '../events';
|
|
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
const _responseTime = responseTime.default;
|
|
|
|
export function responseTimeMetrics(eventBus: EventEmitter): any {
|
|
return _responseTime((req, res, time) => {
|
|
const { statusCode } = res;
|
|
|
|
const pathname = req.route ? req.baseUrl + req.route.path : '(hidden)';
|
|
|
|
const timingInfo = {
|
|
path: pathname,
|
|
method: req.method,
|
|
statusCode,
|
|
time,
|
|
};
|
|
eventBus.emit(REQUEST_TIME, timingInfo);
|
|
});
|
|
}
|