| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import { Request, Response, NextFunction } from 'express';
- /**
- * 请求日志中间件
- */
- export const loggerMiddleware = (
- req: Request,
- res: Response,
- next: NextFunction
- ): void => {
- const start = Date.now();
- res.on('finish', () => {
- const duration = Date.now() - start;
- const { method, originalUrl, ip } = req;
- const { statusCode } = res;
- console.log(
- `${method} ${originalUrl} ${statusCode} ${duration}ms - ${ip}`
- );
- });
- next();
- };
|