Pass version to UI through AppConfig, instead of login payload.master

This makes the version info updated with a browser refresh (no need to logout and login again)
This commit is contained in:
Deluan
2020-04-08 11:00:30 -04:00
parent db246900a6
commit 089a92157f
6 changed files with 35 additions and 14 deletions
+21 -10
View File
@@ -19,22 +19,16 @@ func ServeIndex(ds model.DataStore, fs http.FileSystem) http.HandlerFunc {
c, err := ds.User(r.Context()).CountAll()
firstTime := c == 0 && err == nil
t := template.New("initial state")
indexHtml, err := fs.Open("index.html")
if err != nil {
log.Error(r, "Could not find `index.html` template", err)
}
indexStr, err := ioutil.ReadAll(indexHtml)
if err != nil {
log.Error(r, "Could not read from `index.html`", err)
}
t, _ = t.Parse(string(indexStr))
t := getIndexTemplate(r, fs)
appConfig := map[string]interface{}{
"version": consts.Version(),
"firstTime": firstTime,
"baseURL": strings.TrimSuffix(conf.Server.BaseURL, "/"),
"loginBackgroundURL": conf.Server.UILoginBackgroundURL,
}
j, _ := json.Marshal(appConfig)
data := map[string]interface{}{
"AppConfig": string(j),
"Version": consts.Version(),
@@ -45,3 +39,20 @@ func ServeIndex(ds model.DataStore, fs http.FileSystem) http.HandlerFunc {
}
}
}
func getIndexTemplate(r *http.Request, fs http.FileSystem) *template.Template {
t := template.New("initial state")
indexHtml, err := fs.Open("index.html")
if err != nil {
log.Error(r, "Could not find `index.html` template", err)
}
indexStr, err := ioutil.ReadAll(indexHtml)
if err != nil {
log.Error(r, "Could not read from `index.html`", err)
}
t, err = t.Parse(string(indexStr))
if err != nil {
log.Error(r, "Error parsing `index.html`", err)
}
return t
}