fix ip processing bug: ip was sometimes an array

This commit is contained in:
Evan
2024-12-30 13:24:09 -08:00
parent e9d9fe1d98
commit 0693b5db65
2 changed files with 4 additions and 5 deletions
-3
View File
@@ -166,15 +166,12 @@ function anonymizeIPv6(ipv6: string): string | null {
}
function anonymizeIP(ip: string): string | null {
console.log(`anonymize got ip: ${ip}`)
const ipv4Result = anonymizeIPv4(ip);
if (ipv4Result) {
console.log(`got ipv4 result: ${ipv4Result}`)
return ipv4Result;
}
const ipv6 = anonymizeIPv6(ip);
console.log(`got ipv6: ${ipv6}`)
return ipv6
}
+4 -2
View File
@@ -131,10 +131,12 @@ wss.on('connection', (ws, req) => {
})
if (clientMsg.type == "join") {
const forwarded = req.headers['x-forwarded-for']
const ip = Array.isArray(forwarded)
let ip = Array.isArray(forwarded)
? forwarded[0] // Get the first IP if it's an array
: forwarded || req.socket.remoteAddress;
console.log(`dev: ip address: ${ip}`)
if (Array.isArray(ip)) {
ip = ip[0]
}
gm.addClient(
new Client(
clientMsg.clientID,