Spaces:
Sleeping
Sleeping
Download backend/src/middleware/requestLogger.ts from jacqueshuang/ng: direct link, hf CLI and curl.
- Browser
- Download file 592 Bytes
-
https://huggingface.co/spaces/jacqueshuang/ng/resolve/main/backend/src/middleware/requestLogger.ts
- Command line
-
hf download hf://spaces/jacqueshuang/ng/backend/src/middleware/requestLogger.ts
-
curl -L -o requestLogger.ts https://huggingface.co/spaces/jacqueshuang/ng/resolve/main/backend/src/middleware/requestLogger.ts
592 Bytes
| import { Request, Response, NextFunction } from "express"; | |
| import { logger } from "../utils/logger"; | |
| const excludePaths = ["/tele-images/"]; | |
| export const requestLogger = () => { | |
| return (req: Request, res: Response, next: NextFunction) => { | |
| const start = Date.now(); | |
| res.on("finish", () => { | |
| if (excludePaths.includes(req.path)) { | |
| return; | |
| } | |
| const duration = Date.now() - start; | |
| logger.info({ | |
| method: req.method, | |
| path: req.path, | |
| status: res.statusCode, | |
| duration: `${duration}ms`, | |
| }); | |
| }); | |
| next(); | |
| }; | |
| }; | |