HeliumTS is under active development and may have bugs or breaking changes. Report issues on GitHub.
Proxy Configuration for IP Detection
When deploying behind proxies (like Vercel, Cloudflare, AWS ALB, etc.), accurate client IP detection is crucial for rate limiting and connection limits. Without proper proxy configuration, the system might identify the proxy server's IP instead of the real client IP.
Configuration
Use the trustProxyDepth setting in your helium.config.ts:
1import type { HeliumConfig } from "heliumts/server";23const config: HeliumConfig = {4 trustProxyDepth: 1, // Set based on your deployment5};67export default config;
How It Works
With trustProxyDepth: 0, Helium ignores forwarding headers and uses the direct socket address. With proxy trust enabled, it selects the client address from X-Forwarded-For by counting trusted hops from the right, including the direct peer.
1X-Forwarded-For: untrusted-prefix, client, proxy2trustProxyDepth: 1 -> proxy3trustProxyDepth: 2 -> client
When X-Forwarded-For is absent, Helium can use CF-Connecting-IP, True-Client-IP, then X-Real-IP. Forwarded values must be valid IP addresses; an invalid or too-short chain falls back to the socket address. Your trusted proxy must overwrite provider-specific headers.
Common Deployment Scenarios
Vercel / Netlify / Railway / DigitalOcean APPs
trustProxyDepth: 1
Use 1 only when your deployment has exactly one trusted proxy hop; check the actual proxy chain for your platform.
Cloudflare → Your Server
trustProxyDepth: 1
Helium uses the rightmost forwarded address when X-Forwarded-For is present, otherwise a valid provider-specific header.
Cloudflare → Nginx → Node.js
trustProxyDepth: 2
With two proxy layers (Nginx + Cloudflare).
Local Development
trustProxyDepth: 0 (Default)
No proxies in local development.
Security Considerations
- Setting trustProxyDepth Too Low: Rate limiting will apply to the proxy IP, affecting all users.
- Setting trustProxyDepth Too High: Potential security risk if
X-Forwarded-Foris spoofed.
Best Practice: Always set trustProxyDepth to match your exact proxy configuration.