Fix routing tree 0.4 (#532)

* Marshal regexp into string for routing tree

* Add /lib to dev/static mode switch

* Regenerate assets

* Remove comment and format anon struct

* Simplify configJSON marshaling

Make config.Regexp json-Marshalable.

* Correctly escape json string

* Use value pointer for configJSON
This commit is contained in:
stuart nelson 2016-10-17 15:07:25 +02:00 committed by Fabian Reinartz
parent bbd9d2377e
commit 80c85d8dd4
4 changed files with 65 additions and 54 deletions

View File

@ -14,6 +14,7 @@
package config
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
@ -455,3 +456,8 @@ func (re *Regexp) MarshalYAML() (interface{}, error) {
}
return nil, nil
}
// MarshalJSON implements the json.Marshaler interface.
func (re Regexp) MarshalJSON() ([]byte, error) {
return json.Marshal(re.String())
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

17
web.go
View File

@ -59,6 +59,11 @@ func Register(r *route.Router, reloadCh chan<- struct{}, devMode bool) {
r.Get("/", func(w http.ResponseWriter, req *http.Request) {
http.ServeFile(w, req, "ui/app/index.html")
})
r.Get("/lib/*filepath", func(w http.ResponseWriter, req *http.Request) {
fp := route.Param(route.Context(req), "filepath")
log.Infoln("Serving file", fp)
http.ServeFile(w, req, fmt.Sprintf("ui/lib/%s", fp))
})
} else {
r.Get("/app/*filepath", ihf("app_files",
func(w http.ResponseWriter, req *http.Request) {
@ -70,13 +75,13 @@ func Register(r *route.Router, reloadCh chan<- struct{}, devMode bool) {
r.Get("/", ihf("index", func(w http.ResponseWriter, req *http.Request) {
serveAsset(w, req, "ui/app/index.html")
}))
r.Get("/lib/*filepath", ihf("lib_files",
func(w http.ResponseWriter, req *http.Request) {
fp := route.Param(route.Context(req), "filepath")
serveAsset(w, req, filepath.Join("ui/lib", fp))
},
))
}
r.Get("/lib/*filepath", ihf("lib_files",
func(w http.ResponseWriter, req *http.Request) {
fp := route.Param(route.Context(req), "filepath")
serveAsset(w, req, filepath.Join("ui/lib", fp))
},
))
r.Get("/metrics", prometheus.Handler().ServeHTTP)