mirror of
https://github.com/certd/certd.git
synced 2026-07-10 06:57:31 +08:00
🔱: [server] sync upgrade with 21 commits [trident-sync]
Update README.md
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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');
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user