mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2025-12-27 20:10:16 +00:00
22 lines
650 B
TypeScript
22 lines
650 B
TypeScript
import { Provide } from '@midwayjs/decorator';
|
|
import { IWebMiddleware, IMidwayWebNext, IMidwayWebContext } from '@midwayjs/web';
|
|
|
|
/**
|
|
* 日志中间件
|
|
*/
|
|
@Provide()
|
|
export class BaseLogsMiddleware implements IWebMiddleware {
|
|
|
|
resolve() {
|
|
return async (ctx: IMidwayWebContext, next: IMidwayWebNext) => {
|
|
console.log('日志')
|
|
// 控制器前执行的逻辑
|
|
const startTime = Date.now();
|
|
// 执行下一个 Web 中间件,最后执行到控制器
|
|
await next();
|
|
// 控制器之后执行的逻辑
|
|
console.log(Date.now() - startTime);
|
|
};
|
|
}
|
|
|
|
} |