From 845bfe1e025e562dde5dd035be79b2b51818d1cb Mon Sep 17 00:00:00 2001 From: Marces Engel Date: Wed, 2 Aug 2023 12:02:30 +0200 Subject: [PATCH] Added number of hops to function example for "behind-proxies" page `proxy-addr` not only passes the ip but also the index of the hop to the callback. This could be noted in the documentation, as it's useful for private servers behind a public load balancer which, in theory, is accessible to the public internet but should be proxied by a CDN. In this example the first hop can always be trusted (LoadBalancer -> API) but the second hop would depend on the IP of the incoming request (either CDN -> LB or internet -> LB). --- en/guide/behind-proxies.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/en/guide/behind-proxies.md b/en/guide/behind-proxies.md index b645093e1e..8d306f87ab 100755 --- a/en/guide/behind-proxies.md +++ b/en/guide/behind-proxies.md @@ -67,8 +67,8 @@ When using this setting, it is important to ensure there are not multiple, diffe Custom trust implementation. ```js -app.set('trust proxy', (ip) => { - if (ip === '127.0.0.1' || ip === '123.123.123.123') return true // trusted IPs +app.set('trust proxy', (ip, i) => { + if (i < 1 || ip === '123.123.123.123') return true // first hop or trusted IP else return false }) ```