Mercurial > gemma
changeset 3104:19fc84a98479
Added "published-config" field to configuration.
It's a path to a published JSON file (after login) to give additional parameters to the client.
Reached by GET /api/system/config
Currently the field "osm-url" is used by the client to determine the URL of the OSM server for
the background layer.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2019 15:31:43 +0200 |
parents | 247e78ba2bf7 |
children | e53ff5bcc020 |
files | client/src/components/map/Map.vue pkg/config/config.go pkg/controllers/routes.go pkg/controllers/system.go |
diffstat | 4 files changed, 38 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/components/map/Map.vue Thu Apr 25 13:11:41 2019 +0200 +++ b/client/src/components/map/Map.vue Thu Apr 25 15:31:43 2019 +0200 @@ -219,13 +219,13 @@ }, mounted() { // ToDo set path to correct endpoint in order to retrieve an OSM URL - HTTP.get("/users", { + HTTP.get("/system/config", { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { const { url } = response.data; const config = {}; - if (url) config["url"] = url; + if (url) config["osm-url"] = url; this.layers.config.unshift( new TileLayer({ id: "OPENSTREETMAP",
--- a/pkg/config/config.go Thu Apr 25 13:11:41 2019 +0200 +++ b/pkg/config/config.go Thu Apr 25 15:31:43 2019 +0200 @@ -106,6 +106,10 @@ // If left empty the system default for temporary files is used. func TmpDir() string { return viper.GetString("tmp-dir") } +// PublishedConfig is a name of a JSON file where extra configuration is stored +// to be served to to the web client. +func PublishedConfig() string { return viper.GetString("published-config") } + var ( proxyKeyOnce sync.Once proxyKey []byte @@ -267,6 +271,8 @@ "Defaults to system temp directory.") str("schema-dirs", ".", "Directories to find XSD schema files in (recursive).") + + str("published-config", "", "path to a config file served to client.") } var (
--- a/pkg/controllers/routes.go Thu Apr 25 13:11:41 2019 +0200 +++ b/pkg/controllers/routes.go Thu Apr 25 15:31:43 2019 +0200 @@ -74,6 +74,11 @@ })).Methods(http.MethodGet) // System Settings + api.Handle("/system/config", any(&JSONHandler{ + Handle: getSystemConfig, + NoConn: true, + })).Methods(http.MethodGet) + api.Handle("/system/style/{feature}/{attr}", any(&JSONHandler{ Handle: getFeatureStyle, })).Methods(http.MethodGet)
--- a/pkg/controllers/system.go Thu Apr 25 13:11:41 2019 +0200 +++ b/pkg/controllers/system.go Thu Apr 25 15:31:43 2019 +0200 @@ -14,12 +14,14 @@ package controllers import ( + "bytes" "database/sql" "fmt" "io/ioutil" "net/http" "strings" + "gemma.intevation.de/gemma/pkg/config" "gemma.intevation.de/gemma/pkg/models" "github.com/gorilla/mux" ) @@ -78,6 +80,29 @@ return } +func getSystemConfig( + _ interface{}, req *http.Request, + _ *sql.Conn, +) (jr JSONResult, err error) { + + cfg := config.PublishedConfig() + if cfg == "" { + err = JSONError{ + Code: http.StatusNotFound, + Message: "No published configuration found.", + } + return + } + + var data []byte + if data, err = ioutil.ReadFile(cfg); err != nil { + return + } + + jr = JSONResult{Result: bytes.NewReader(data)} + return +} + // Map/Feature style end points func getFeatureStyle(