traefik/pkg/api/dashboard.go

34 lines
840 B
Go
Raw Normal View History

package api
import (
"net/http"
2019-08-03 01:58:23 +00:00
"github.com/containous/traefik/v2/pkg/log"
2019-02-18 06:52:03 +00:00
assetfs "github.com/elazarl/go-bindata-assetfs"
2019-08-03 01:58:23 +00:00
"github.com/gorilla/mux"
)
// DashboardHandler expose dashboard routes
type DashboardHandler struct {
Assets *assetfs.AssetFS
}
2018-11-14 09:18:03 +00:00
// Append add dashboard routes on a router
func (g DashboardHandler) Append(router *mux.Router) {
if g.Assets == nil {
2018-11-14 09:18:03 +00:00
log.WithoutContext().Error("No assets for dashboard")
return
}
// Expose dashboard
2018-04-27 11:12:04 +00:00
router.Methods(http.MethodGet).
Path("/").
HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
http.Redirect(response, request, request.Header.Get("X-Forwarded-Prefix")+"/dashboard/", http.StatusFound)
2018-04-27 11:12:04 +00:00
})
router.Methods(http.MethodGet).
PathPrefix("/dashboard/").
Handler(http.StripPrefix("/dashboard/", http.FileServer(g.Assets)))
}