nodeJSはユーザーIPを取得する
427 ワード
function getClientIp(req) {
var ipAddress;
var forwardedIpsStr = req.header('x-forwarded-for');
if (forwardedIpsStr) {
var forwardedIps = forwardedIpsStr.split(',');
ipAddress = forwardedIps[0];
}
if (!ipAddress) {
ipAddress = req.connection.remoteAddress;
}
return ipAddress;
};