122f4c731f
- we do not log both the ip if the user is signed in, as this may be a privacy issue - the ip is only logged if there is no associated user information
23 lines
546 B
JavaScript
23 lines
546 B
JavaScript
const getIpFromRequest = (req) => {
|
|
let ip
|
|
try {
|
|
ip =
|
|
req.headers['cf-connecting-ip'] ||
|
|
req.headers['true-client-ip'] ||
|
|
req.headers['x-real-ip'] ||
|
|
req.headers['x-forwarded-for'] ||
|
|
req.ip ||
|
|
req.connection.remoteAddress ||
|
|
''
|
|
} catch {
|
|
ip = ''
|
|
}
|
|
const ignorePrefixes = ['192.168.', '10.', '127.', '172.1', '172.2', '172.3', '::']
|
|
|
|
for (const ipPrefix of ignorePrefixes)
|
|
if (ip.startsWith(ipPrefix) || ip === '') return null
|
|
return ip
|
|
}
|
|
|
|
module.exports = { getIpFromRequest }
|