# HG changeset patch # User Sascha L. Teichmann # Date 1556199103 -7200 # Node ID 19fc84a984797bbeb32dae6bb766078e04cf4926 # Parent 247e78ba2bf7bed4af0b73df7b510f59bf7c08b7 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. diff -r 247e78ba2bf7 -r 19fc84a98479 client/src/components/map/Map.vue --- 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", diff -r 247e78ba2bf7 -r 19fc84a98479 pkg/config/config.go --- 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 ( diff -r 247e78ba2bf7 -r 19fc84a98479 pkg/controllers/routes.go --- 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) diff -r 247e78ba2bf7 -r 19fc84a98479 pkg/controllers/system.go --- 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(