feat(logging): add logging middleware for HTTP requests and update API timeout

- Introduce LoggingMiddleware to log incoming requests and their response times
- Update AppModule to apply the new logging middleware globally
- Increase API request timeout from 10 seconds to 60 seconds
- Modify PromptString to include additional project types of interest
This commit is contained in:
dmy
2026-01-15 21:52:40 +08:00
parent 3033eb622f
commit 811ad927f3
5 changed files with 39 additions and 4 deletions

View File

@@ -0,0 +1,29 @@
import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import { CustomLogger } from './logger.service';
@Injectable()
export class LoggingMiddleware implements NestMiddleware {
constructor(private readonly logger: CustomLogger) {
this.logger.setContext('HTTP');
}
use(req: Request, res: Response, next: NextFunction) {
const { method, originalUrl, ip } = req;
const userAgent = req.get('user-agent') || '';
const startTime = Date.now();
// 收到请求时立即输出
this.logger.debug(`--> ${method} ${originalUrl} - ${ip} - ${userAgent}`);
res.on('finish', () => {
const { statusCode } = res;
const duration = Date.now() - startTime;
this.logger.debug(
`<-- ${method} ${originalUrl} ${statusCode} - ${duration}ms`,
);
});
next();
}
}