guoziyun hace 1 año
padre
commit
d73be3f871
Se han modificado 1 ficheros con 2 adiciones y 1 borrados
  1. 2 1
      app.js

+ 2 - 1
app.js

@@ -61,7 +61,8 @@ app.use(bodyParser.urlencoded({
 // 自定义日志中间件
 app.use((req, res, next) => {
   const now = new Date().toISOString();
-  console.log(`[${now}] ${req.method} ${req.url}`);
+  const ip = req.headers['x-forwarded-for'] || req.ip;
+  console.log(`[${now}] ${ip} ${req.method} ${req.url}`);
   next(); // 调用 next() 函数,将请求传递给下一个中间件或路由处理程序
 });