mirror of
https://github.com/upstash/context7.git
synced 2025-11-25 14:37:27 +00:00
CTX7-272: ip address header
This commit is contained in:
parent
68143b6509
commit
96be3f629d
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user