K-EXPLORER: fix the k8s/local ws issue

This commit is contained in:
niusmallnan 2021-04-14 13:34:14 +08:00
parent 5049a746da
commit 255623bd7c
2 changed files with 17 additions and 2 deletions

View File

@ -48,9 +48,9 @@ func New(cfg *rest.Config, sf schema.Factory, authMiddleware auth.Middleware, ne
APIRoot: w(a.apiHandler(apiRoot)),
}
if routerFunc == nil {
return a.server, router.Routes(handlers), nil
return a.server, rewriteLocalCluster(router.Routes(handlers)), nil
}
return a.server, routerFunc(handlers), nil
return a.server, rewriteLocalCluster(routerFunc(handlers)), nil
}
type apiServer struct {

View File

@ -1,6 +1,9 @@
package handler
import (
"net/http"
"strings"
"github.com/gorilla/mux"
"github.com/rancher/apiserver/pkg/types"
"github.com/rancher/steve/pkg/attributes"
@ -35,3 +38,15 @@ func k8sAPI(sf schema.Factory, apiOp *types.APIRequest) {
func apiRoot(sf schema.Factory, apiOp *types.APIRequest) {
apiOp.Type = "apiRoot"
}
func rewriteLocalCluster(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
if strings.HasPrefix(req.URL.Path, "/k8s/clusters/local") {
req.URL.Path = strings.TrimPrefix(req.URL.Path, "/k8s/clusters/local")
if req.URL.Path == "" {
req.URL.Path = "/"
}
}
next.ServeHTTP(rw, req)
})
}