2017-11-09 15:12:04 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/containous/mux"
|
2018-05-25 13:10:04 +00:00
|
|
|
"github.com/containous/traefik/log"
|
2017-11-09 15:12:04 +00:00
|
|
|
"github.com/elazarl/go-bindata-assetfs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DashboardHandler expose dashboard routes
|
2018-05-25 13:10:04 +00:00
|
|
|
type DashboardHandler struct {
|
|
|
|
Assets *assetfs.AssetFS
|
|
|
|
}
|
2017-11-09 15:12:04 +00:00
|
|
|
|
2018-11-14 09:18:03 +00:00
|
|
|
// Append add dashboard routes on a router
|
|
|
|
func (g DashboardHandler) Append(router *mux.Router) {
|
2018-05-25 13:10:04 +00:00
|
|
|
if g.Assets == nil {
|
2018-11-14 09:18:03 +00:00
|
|
|
log.WithoutContext().Error("No assets for dashboard")
|
2018-05-25 13:10:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-11-09 15:12:04 +00:00
|
|
|
// Expose dashboard
|
2018-04-27 11:12:04 +00:00
|
|
|
router.Methods(http.MethodGet).
|
|
|
|
Path("/").
|
|
|
|
HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
|
2019-01-30 15:24:07 +00:00
|
|
|
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).
|
|
|
|
Path("/dashboard/status").
|
|
|
|
HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
|
2019-01-30 15:24:07 +00:00
|
|
|
http.Redirect(response, request, "/dashboard/", http.StatusFound)
|
2018-04-27 11:12:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
router.Methods(http.MethodGet).
|
|
|
|
PathPrefix("/dashboard/").
|
2018-05-25 13:10:04 +00:00
|
|
|
Handler(http.StripPrefix("/dashboard/", http.FileServer(g.Assets)))
|
2017-11-09 15:12:04 +00:00
|
|
|
}
|