CTX7-272: ip address header

This commit is contained in:
buggyhunter 2025-08-01 12:50:16 +03:00
parent 68143b6509
commit 96be3f629d

View File

@ -49,14 +49,12 @@ const sseTransports: Record<string, SSEServerTransport> = {};
function getClientIp(req: IncomingMessage): string | undefined {
// Check both possible header casings
const forwardedFor =
req.headers["x-forwarded-for"] ||
req.headers["X-Forwarded-For"];
const forwardedFor = req.headers["x-forwarded-for"] || req.headers["X-Forwarded-For"];
if (forwardedFor) {
// X-Forwarded-For can contain multiple IPs
const ips = Array.isArray(forwardedFor) ? forwardedFor[0] : forwardedFor;
const ipList = ips.split(",").map(ip => ip.trim());
const ipList = ips.split(",").map((ip) => ip.trim());
// Find the first public IP address
for (const ip of ipList) {