mirror of
https://github.com/certd/certd.git
synced 2026-06-27 22:17:35 +08:00
25 lines
717 B
TypeScript
25 lines
717 B
TypeScript
import { Provide } from '@midwayjs/core';
|
|
import { IWebMiddleware, IMidwayKoaContext, NextFunction } from '@midwayjs/koa';
|
|
import { logger } from '../utils/logger.js';
|
|
|
|
@Provide()
|
|
export class ReportMiddleware implements IWebMiddleware {
|
|
resolve() {
|
|
return async (ctx: IMidwayKoaContext, next: NextFunction) => {
|
|
const { url } = ctx;
|
|
logger.info('请求开始:', url);
|
|
const startTime = Date.now();
|
|
await next();
|
|
if (ctx.status !== 200) {
|
|
logger.error(
|
|
'请求失败:',
|
|
url,
|
|
ctx.status,
|
|
Date.now() - startTime + 'ms'
|
|
);
|
|
}
|
|
logger.info('请求完成:', url, ctx.status, Date.now() - startTime + 'ms');
|
|
};
|
|
}
|
|
}
|