# HG changeset patch # User Sascha L. Teichmann # Date 1545313163 -3600 # Node ID eadf84bb0e98206d749bb4e34e0c2282533da0e9 # Parent 1fde2f48977bf60c137bd643c5bd481b7caee644 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} . diff -r 1fde2f48977b -r eadf84bb0e98 example_conf.toml --- 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: diff -r 1fde2f48977b -r eadf84bb0e98 pkg/config/config.go --- 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 (