15 lines
435 B
TypeScript
15 lines
435 B
TypeScript
import { Context, Next } from 'koa';
|
|
|
|
export const performanceLogger = async (ctx: Context, next: Next) => {
|
|
await next();
|
|
const rt = ctx.response.get('X-Response-Time');
|
|
console.log(`${ctx.method} ${ctx.url} - ${rt}`);
|
|
};
|
|
|
|
export const performanceTimer = async (ctx: Context, next: Next) => {
|
|
const start = Date.now();
|
|
await next();
|
|
const ms = Date.now() - start;
|
|
ctx.set('X-Response-Time', `${ms}ms`);
|
|
};
|