mirror of
https://github.com/certd/certd.git
synced 2026-04-15 05:00:52 +08:00
29 lines
726 B
TypeScript
29 lines
726 B
TypeScript
import { Provide } from '@midwayjs/decorator';
|
|
import {
|
|
IWebMiddleware,
|
|
IMidwayKoaContext,
|
|
NextFunction,
|
|
} from '@midwayjs/koa';
|
|
import { logger } from '../utils/logger';
|
|
|
|
@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');
|
|
};
|
|
}
|
|
}
|