【发布时间】:2019-12-17 06:15:39
【问题描述】:
我正在尝试使用以下代码控制日志客户端,但我的超级终端没有显示任何内容。
var getClientIp = function(req) {
return (req.headers["X-Forwarded-For"] ||
req.headers["x-forwarded-for"] ||
'').split(',')[0] ||
req.client.remoteAddress;
}; //i replaces this section with different codes but nothing works
const express = require("express");
const app = express();
app.use(express.static(__dirname + '/'));
app.get("/", function(req,res){
res.sendFile(__dirname + "/index.html");
var getClientIp = function(req) {
return (req.headers["X-Forwarded-For"] ||
req.headers["x-forwarded-for"] ||
'').split(',')[0] ||
req.client.remoteAddress;
};
onsole.log(getClientIp);});
app.listen(3000, function(){
console.log("server is started on port 3000");});
【问题讨论】:
-
你的
onsole.log应该是console.log -
嗨,欢迎来到 StackOverflow。我们喜欢干净、有格式的问题!如果您想改进您的问题,请考虑格式化您的代码(并修复拼写错误),以便希望提供帮助的人可以更轻松地提供帮助!
标签: javascript node.js ip