mirror of
https://github.com/jiangrui1994/CloudSaver.git
synced 2026-01-12 16:18:45 +08:00
Refactoring the backend
This commit is contained in:
18
backend/src/middleware/requestLogger.ts
Normal file
18
backend/src/middleware/requestLogger.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
export const requestLogger = () => {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
const start = Date.now();
|
||||
res.on("finish", () => {
|
||||
const duration = Date.now() - start;
|
||||
logger.info({
|
||||
method: req.method,
|
||||
path: req.path,
|
||||
status: res.statusCode,
|
||||
duration: `${duration}ms`,
|
||||
});
|
||||
});
|
||||
next();
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user