mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
parent
d65bf6ae61
commit
79f2528419
2 changed files with 12 additions and 6 deletions
|
|
@ -122,7 +122,7 @@ the way that the kolide server works.
|
|||
|
||||
var apiHandler, frontendHandler http.Handler
|
||||
{
|
||||
frontendHandler = prometheus.InstrumentHandler("get_frontend", service.ServeFrontend())
|
||||
frontendHandler = prometheus.InstrumentHandler("get_frontend", service.ServeFrontend(httpLogger))
|
||||
apiHandler = service.MakeHandler(ctx, svc, config.Auth.JwtKey, httpLogger)
|
||||
|
||||
setupRequired, err := service.RequireSetup(svc)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
assetfs "github.com/elazarl/go-bindata-assetfs"
|
||||
"github.com/go-kit/kit/log"
|
||||
)
|
||||
|
||||
func newBinaryFileSystem(root string) *assetfs.AssetFS {
|
||||
|
|
@ -17,26 +18,31 @@ func newBinaryFileSystem(root string) *assetfs.AssetFS {
|
|||
}
|
||||
}
|
||||
|
||||
func ServeFrontend() http.Handler {
|
||||
func ServeFrontend(logger log.Logger) http.Handler {
|
||||
herr := func(w http.ResponseWriter, err string) {
|
||||
logger.Log("err", err)
|
||||
http.Error(w, err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fs := newBinaryFileSystem("/frontend")
|
||||
file, err := fs.Open("templates/react.tmpl")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
herr(w, "load react template: "+err.Error())
|
||||
return
|
||||
}
|
||||
data, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
herr(w, "read bindata file: "+err.Error())
|
||||
return
|
||||
}
|
||||
t, err := template.New("react").Parse(string(data))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
herr(w, "create react template: "+err.Error())
|
||||
return
|
||||
}
|
||||
if err := t.Execute(w, nil); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
herr(w, "execute react template: "+err.Error())
|
||||
return
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue