Express Backend Configuration
Configure your Express backend to trust Relay edge limits.
Trusting Proxies
Because Relay sits between your users and your backend, your Express application will see the request as coming from Relay's IP address rather than the original client's IP. To ensure rate limiting and IP-based logic works correctly on your end (if needed), you must configure Express to trust the proxy.
Add the following configuration to your Express app:
Handling Client IPs
Relay automatically appends the original client IP to the x-forwarded-for header and explicitly sets the x-relay-client-ip header. You can use these headers to identify the real origin of the request.
- x-forwarded-for: Standard header showing the originating IP address.
- x-relay-client-ip: Relay-specific header for reliable IP identification.
Enforcing Relay Traffic
To prevent malicious actors from bypassing Relay and hitting your backend directly, you should write a middleware that rejects any requests that do not originate from Relay. You can do this by validating the presence of Relay-specific headers or by whitelisting Relay's IP addresses.