This repository has been archived on 2023-05-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
auth/lib/middleware/performance.ts
mifi 92d43edd7a
All checks were successful
continuous-integration/drone/push Build is passing
Only warning now... Green pipeline?
2023-05-02 11:45:41 -04:00

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 perfromanceTimer = async (ctx: Context, next: Next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
ctx.set('X-Response-Time', `${ms}ms`);
};