From 1eab25f89fd305e630aa5b362e0532c72bb51718 Mon Sep 17 00:00:00 2001 From: Rui Yang Date: Mon, 21 Sep 2020 23:26:35 -0400 Subject: [PATCH] use web host url for asset hosting Signed-off-by: Rui Yang Co-authored-by: Aidan Oldershaw --- server/server.go | 3 +++ server/templates.go | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/server/server.go b/server/server.go index 79c5f5a0..baf2b30a 100644 --- a/server/server.go +++ b/server/server.go @@ -121,6 +121,9 @@ type WebConfig struct { // Map of extra values passed into the templates Extra map[string]string + + // Defaults to issuer URL + HostURL string } func value(val, defaultValue time.Duration) time.Duration { diff --git a/server/templates.go b/server/templates.go index b23083ba..1c04a68e 100644 --- a/server/templates.go +++ b/server/templates.go @@ -53,12 +53,17 @@ func loadTemplates(c WebConfig, issuerPath string) (*templates, error) { c.LogoURL = "theme/logo.png" } + hostURL := issuerPath + if c.HostURL != "" { + hostURL = c.HostURL + } + funcs := template.FuncMap{ "issuer": func() string { return c.Issuer }, "logo": func() string { return c.LogoURL }, - "url": func(reqPath, assetPath string) string { return relativeURL(issuerPath, reqPath, assetPath) }, + "url": func(reqPath, assetPath string) string { return relativeURL(hostURL, reqPath, assetPath) }, "theme": func(reqPath, assetPath string) string { - return relativeURL(issuerPath, reqPath, path.Join("themes", c.Theme, assetPath)) + return relativeURL(hostURL, reqPath, path.Join("themes", c.Theme, assetPath)) }, "lower": strings.ToLower, "extra": func(k string) string { return c.Extra[k] },