guoziyun 1 年間 前
コミット
d73be3f871
1 ファイル変更2 行追加1 行削除
  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() 函数,将请求传递给下一个中间件或路由处理程序
 });