From 5247afcfc659057c2c8e3c15a08d5400f5b553c7 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Mon, 30 Aug 2021 18:39:24 -0500 Subject: [PATCH] Fix scheme issue with X-Forwarded-Proto --- server/Caddyfile | 4 ++++ src/website/requesthandling.go | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/server/Caddyfile b/server/Caddyfile index c354ea31..adfde2a2 100644 --- a/server/Caddyfile +++ b/server/Caddyfile @@ -8,6 +8,10 @@ file_server { root /home/hmn/hmn } + header { + Access-Control-Allow-Origin * + Access-Control-Allow-Methods "GET, OPTIONS" + } } handle { reverse_proxy localhost:9001 diff --git a/src/website/requesthandling.go b/src/website/requesthandling.go index e7a9dea3..daeebd8d 100644 --- a/src/website/requesthandling.go +++ b/src/website/requesthandling.go @@ -144,7 +144,7 @@ func (c *RequestContext) FullUrl() string { if scheme == "" { proto, hasProto := c.Req.Header["X-Forwarded-Proto"] if hasProto { - scheme = fmt.Sprintf("%s://", proto) + scheme = fmt.Sprintf("%s://", proto[0]) } } @@ -155,6 +155,7 @@ func (c *RequestContext) FullUrl() string { scheme = "http://" } } + return scheme + c.Req.Host + c.Req.URL.String() }