implement x-forwarded-proto

This commit is contained in:
orangix
2026-01-05 08:05:49 +01:00
parent 42174c052d
commit 09222a116f
2 changed files with 22 additions and 17 deletions

View File

@@ -9,6 +9,7 @@ type config struct {
Port string Port string
Addr string Addr string
ImgurId string ImgurId string
ProtocolDetection bool
Secure bool Secure bool
FiberPrefork bool FiberPrefork bool
ImageCache bool ImageCache bool
@@ -48,6 +49,7 @@ func LoadConfig() {
Port: port, Port: port,
Addr: addr, Addr: addr,
ImgurId: imgurId, ImgurId: imgurId,
ProtocolDetection: os.Getenv("PROTOCOL_DETECTION") == "true" || os.Getenv("PROTOCOL_DETECTION") == "1",
Secure: os.Getenv("SECURE") == "true", Secure: os.Getenv("SECURE") == "true",
FiberPrefork: os.Getenv("FIBER_PREFORK") == "true", FiberPrefork: os.Getenv("FIBER_PREFORK") == "true",
Privacy: map[string]interface{}{ Privacy: map[string]interface{}{

View File

@@ -3,9 +3,12 @@ package utils
import "github.com/gofiber/fiber/v2" import "github.com/gofiber/fiber/v2"
func GetInstanceUrl(c *fiber.Ctx) string { func GetInstanceUrl(c *fiber.Ctx) string {
proto := "https://" proto := "https"
if !Config.Secure { if !Config.Secure {
proto = "http://" proto = "http"
} }
return proto + c.Hostname() if Config.ProtocolDetection {
proto = c.Get("X-Forwarded-Proto", proto)
}
return proto + "://" + c.Hostname()
} }