Fiber
1. Code
package main
import (
"log"
"os"
"github.com/gofiber/fiber/v3"
)
func main() {
app := fiber.New(fiber.Config{
// the panel's proxy headers: c.Scheme() = https, c.IP() = the visitor's address
TrustProxy: true,
TrustProxyConfig: fiber.TrustProxyConfig{Private: true, Loopback: true},
ProxyHeader: fiber.HeaderXForwardedFor,
})
app.Get("/", func(c fiber.Ctx) error {
return c.JSON(fiber.Map{"scheme": c.Scheme(), "host": c.Hostname(), "client": c.IP()})
})
log.Fatal(app.Listen(":" + os.Getenv("PORT")))
}
Add the dependency with go get github.com/gofiber/fiber/v3; the repository must contain go.mod and go.sum.
2. Project
- Create a project with the Go handler (version stable).
- Build command:
cd src && go build -trimpath -ldflags "-s -w" -o ../app . - Start command:
./app
The build and start commands in the "Handler" block. - Connect the repository in the Git deploy block with the
srcdirectory and click "Deploy".
3. If something goes wrong
c.Scheme()returnshttp, andc.IP()the proxy's address.TrustProxywith trust in private addresses is not set.- Fiber v2. There these settings are called
EnableTrustedProxyCheckandTrustedProxies.