Kind: Function
Source: atloria-monorepo/apps/api/src/analytics/utils/tracking-utils.ts
Extract the client IP from a NestJS/Express request. Checks headers set by reverse proxies and CDNs in this order:
- CF-Connecting-IP (Cloudflare)
- X-Real-IP (nginx default)
- X-Forwarded-For (standard proxy header — first IP in the chain)
- req.ip / connection.remoteAddress (direct connection fallback)
Returns null if nothing usable is found (should be rare in production).
Signature
tsfunction extractClientIp(req: {
headers?: Record<string, string | string[] | undefined>;
ip?: string;
connection?: { remoteAddress?: string };
socket?: { remoteAddress?: string };
}): string | null
Parameters
| Name | Type |
|---|---|
req | `{ |
| headers?: Record<string, string | string[] |
| ip?: string; | |
| connection?: { remoteAddress?: string }; | |
| socket?: { remoteAddress?: string }; | |
| }` |
Returns: string | null
Was this page helpful?