feat(ai): 优化健康日报生成,集成用户健康统计数据并增强视觉提示
This commit is contained in:
24
src/main.ts
24
src/main.ts
@@ -27,15 +27,35 @@ async function bootstrap() {
|
||||
app.use((req, res, next) => {
|
||||
const startTime = Date.now();
|
||||
|
||||
// 捕获响应体
|
||||
const originalSend = res.send;
|
||||
let responseBody: any;
|
||||
res.send = function (body) {
|
||||
responseBody = body;
|
||||
return originalSend.call(this, body);
|
||||
};
|
||||
|
||||
res.on('finish', () => {
|
||||
const duration = Date.now() - startTime;
|
||||
const appVersion = req.headers['x-app-version'] || 'unknown';
|
||||
const logMessage = `${req.method} ${req.originalUrl} ${res.statusCode} ${duration}ms [v${appVersion}]`;
|
||||
|
||||
// 解析响应体
|
||||
let responseStr = '';
|
||||
try {
|
||||
if (typeof responseBody === 'string') {
|
||||
responseStr = responseBody;
|
||||
} else if (responseBody) {
|
||||
responseStr = JSON.stringify(responseBody);
|
||||
}
|
||||
} catch {
|
||||
responseStr = '[Unable to stringify response]';
|
||||
}
|
||||
|
||||
if (res.statusCode >= 400) {
|
||||
logger.error(`${logMessage} - Body: ${JSON.stringify(req.body)}`);
|
||||
logger.error(`${logMessage} - Body: ${JSON.stringify(req.body)} - Response: ${responseStr}`);
|
||||
} else {
|
||||
logger.log(`${logMessage} - Body: ${JSON.stringify(req.body)}`);
|
||||
logger.log(`${logMessage} - Body: ${JSON.stringify(req.body)} - Response: ${responseStr}`);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user