changeset 1644:eadf84bb0e98

New config variable 'external-url'. Deep inside the import queue we don't known the URL we find the server at. We don't have any HTTP request we can derive this information wrong so it needs to be configured. Defaults to http://${web-host}:${web-port} .
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 20 Dec 2018 14:39:23 +0100
parents 1fde2f48977b
children 14bb1289b97b bad32adafef2
files example_conf.toml pkg/config/config.go
diffstat 2 files changed, 34 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/example_conf.toml	Thu Dec 20 14:18:30 2018 +0100
+++ b/example_conf.toml	Thu Dec 20 14:39:23 2018 +0100
@@ -56,6 +56,10 @@
 # Proxy settings for external OGC services
 #proxy-key = "SECRET"
 #proxy-prefix = "http://localhost:8000"
+#
+
+# Server is known on the outside as:
+# external-url = "http://localhost:8000"
 
 # ----------------------------------------------------------------------
 # CORS setup:
--- a/pkg/config/config.go	Thu Dec 20 14:18:30 2018 +0100
+++ b/pkg/config/config.go	Thu Dec 20 14:39:23 2018 +0100
@@ -106,11 +106,12 @@
 func TmpDir() string { return viper.GetString("tmp-dir") }
 
 var (
-	proxyKeyOnce sync.Once
-	proxyKey     []byte
-
+	proxyKeyOnce    sync.Once
+	proxyKey        []byte
 	proxyPrefixOnce sync.Once
 	proxyPrefix     string
+	externalURLOnce sync.Once
+	externalURL     string
 )
 
 // ProxyKey is a crytographic key to sign the URLs generated by the proxy.
@@ -142,13 +143,29 @@
 func ProxyPrefix() string {
 	fetchPrefix := func() {
 		if proxyPrefix == "" {
-			proxyPrefix = fmt.Sprintf("http://%s:%d", WebHost(), WebPort())
+			if proxyPrefix = viper.GetString("proxy-prefix"); proxyPrefix == "" {
+				proxyPrefix = fmt.Sprintf("http://%s:%d", WebHost(), WebPort())
+			}
 		}
 	}
 	proxyPrefixOnce.Do(fetchPrefix)
 	return proxyPrefix
 }
 
+// ExternalURL is the URL to find this server from the outside.
+// It defauls to http://${WebHost}:${WebPort}".
+func ExternalURL() string {
+	fetchExternal := func() {
+		if externalURL == "" {
+			if externalURL = viper.GetString("external-url"); externalURL == "" {
+				externalURL = fmt.Sprintf("http://%s:%d", WebHost(), WebPort())
+			}
+		}
+	}
+	externalURLOnce.Do(fetchExternal)
+	return externalURL
+}
+
 // RootCmd is cobra command to be bound th the cobra/viper infrastructure.
 var RootCmd = &cobra.Command{
 	Use:   "gemma",
@@ -219,10 +236,16 @@
 	str("geoserver-password", "geoserver", "GeoServer password")
 	bl("geoserver-clean", false, "Clean GeoServer setup")
 
-	str("proxy-key", "", `signing key for proxy URLs. Defaults to random key.`)
-	str("proxy-prefix", "", `URL prefix of proxy. Defaults to "http://${web-host}:${web-port}"`)
+	str("proxy-key", "", "signing key for proxy URLs.\n"+
+		"Defaults to random key.")
+	str("proxy-prefix", "", "URL prefix of proxy.\n"+
+		"Defaults to 'http://${web-host}:${web-port}'")
 
-	str("tmp-dir", "", "Temp directory of gemma server. Defaults to system temp directory.")
+	str("external-url", "", "URL to find the server from the outside.\n"+
+		"Defaults to 'http://${web-host}:${web-port}'")
+
+	str("tmp-dir", "", "Temp directory of gemma server.\n"+
+		"Defaults to system temp directory.")
 }
 
 var (