Handle missing index.html template
This commit is contained in:
parent
9f4f2f7381
commit
a0bed9beeb
1 changed files with 8 additions and 5 deletions
|
|
@ -21,10 +21,10 @@ func ServeIndex(ds model.DataStore, fs http.FileSystem) http.HandlerFunc {
|
||||||
c, err := ds.User(r.Context()).CountAll()
|
c, err := ds.User(r.Context()).CountAll()
|
||||||
firstTime := c == 0 && err == nil
|
firstTime := c == 0 && err == nil
|
||||||
|
|
||||||
t := getIndexTemplate(r, fs)
|
t, err := getIndexTemplate(r, fs)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error loading default English translation file", err)
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
appConfig := map[string]interface{}{
|
appConfig := map[string]interface{}{
|
||||||
"version": consts.Version(),
|
"version": consts.Version(),
|
||||||
|
|
@ -54,19 +54,22 @@ func ServeIndex(ds model.DataStore, fs http.FileSystem) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getIndexTemplate(r *http.Request, fs http.FileSystem) *template.Template {
|
func getIndexTemplate(r *http.Request, fs http.FileSystem) (*template.Template, error) {
|
||||||
t := template.New("initial state")
|
t := template.New("initial state")
|
||||||
indexHtml, err := fs.Open("index.html")
|
indexHtml, err := fs.Open("index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(r, "Could not find `index.html` template", err)
|
log.Error(r, "Could not find `index.html` template", err)
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
indexStr, err := ioutil.ReadAll(indexHtml)
|
indexStr, err := ioutil.ReadAll(indexHtml)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(r, "Could not read from `index.html`", err)
|
log.Error(r, "Could not read from `index.html`", err)
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
t, err = t.Parse(string(indexStr))
|
t, err = t.Parse(string(indexStr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(r, "Error parsing `index.html`", err)
|
log.Error(r, "Error parsing `index.html`", err)
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return t
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue