From 7fdb593dc018c6c140fd4b0df3c178ee5122e527 Mon Sep 17 00:00:00 2001 From: Tobias Lindberg Date: Mon, 6 Mar 2023 08:29:06 +0100 Subject: [PATCH] add possibility to set trusted proxies in gin by env --- src/webserver.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/webserver.go b/src/webserver.go index dcec8eb5..1d91caa8 100644 --- a/src/webserver.go +++ b/src/webserver.go @@ -101,8 +101,14 @@ func runWebServer() { ) }) - // Disable proxy feature of gin - _ = router.SetTrustedProxies(nil) + // Set proxy feature of gin + trustedProxies := getEnv("GIN_TRUSTED_PROXIES", "") + if len(trustedProxies) > 0 { + _ = router.SetTrustedProxies(strings.Split(trustedProxies, ",")) + log.Print(strings.Split(trustedProxies, ",")) + } else { + _ = router.SetTrustedProxies(nil) + } // Set the ping endpoint router.GET("/ping", func(c *gin.Context) {