Something went wrong. Try again.
Turning knowledge into answers — a self-hosted RAG-powered AMA platform that turns internal knowledge into accurate, context-aware conversa… ama.inovuslabs.org
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344import type { H3Event } from 'h3'
/** * Extract client IP address from the request event * Handles various proxy headers and fallbacks */export function getClientIP(event: H3Event): string | null { // Check for Cloudflare headers first const cfConnectingIP = getHeader(event, 'cf-connecting-ip') if (cfConnectingIP) { return cfConnectingIP }
// Check for X-Forwarded-For header const xForwardedFor = getHeader(event, 'x-forwarded-for') if (xForwardedFor) { // X-Forwarded-For can contain multiple IPs, take the first one const firstIP = xForwardedFor.split(',')[0].trim() if (firstIP) { return firstIP } }
// Check for X-Real-IP header const xRealIP = getHeader(event, 'x-real-ip') if (xRealIP) { return xRealIP }
// Check for X-Client-IP header const xClientIP = getHeader(event, 'x-client-ip') if (xClientIP) { return xClientIP }
// Fallback to connection remote address const connection = event.node.req.socket if (connection?.remoteAddress) { return connection.remoteAddress }
return null}