hanxuan commited on
Commit
b4a2f88
1 Parent(s): 4960788

细节优化

Browse files
Files changed (1) hide show
  1. app.js +1 -1
app.js CHANGED
@@ -16,7 +16,7 @@ const timeout = 30000; // 访问超时
16
 
17
  // 使用中间件,接收所有请求
18
  app.use((req, res, next) => {
19
- const userIP = req.ip;
20
  const currentDate = new Date().toLocaleString('zh-CN', { hour12: false });
21
  //console.log(`[${currentDate}] 收到来自 IP ${userIP} 的请求`);
22
  res.locals.userIP = userIP; // 将 userIP 存储在 res.locals 中,以便在后续中间件和路由中使用
 
16
 
17
  // 使用中间件,接收所有请求
18
  app.use((req, res, next) => {
19
+ const userIP = req.headers['x-forwarded-for'] || req.socket.remoteAddress || null;
20
  const currentDate = new Date().toLocaleString('zh-CN', { hour12: false });
21
  //console.log(`[${currentDate}] 收到来自 IP ${userIP} 的请求`);
22
  res.locals.userIP = userIP; // 将 userIP 存储在 res.locals 中,以便在后续中间件和路由中使用