/** * Best-effort client IP from standard proxy headers. * Returns `'unknown'` when nothing usable is present. */ export function getClientIp(req: Request): string { const forwarded = req.headers.get('x-forwarded-for') if (forwarded) { const first = forwarded.split(',')[0] if (first && first.trim()) return first.trim() } const real = req.headers.get('x-real-ip') if (real && real.trim()) return real.trim() return 'unknown' }