mirror of
https://github.com/niusmallnan/steve.git
synced 2025-08-11 02:01:46 +00:00
K-EXPLORER: fix the k8s/local ws issue
This commit is contained in:
parent
5049a746da
commit
255623bd7c
@ -48,9 +48,9 @@ func New(cfg *rest.Config, sf schema.Factory, authMiddleware auth.Middleware, ne
|
|||||||
APIRoot: w(a.apiHandler(apiRoot)),
|
APIRoot: w(a.apiHandler(apiRoot)),
|
||||||
}
|
}
|
||||||
if routerFunc == nil {
|
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 {
|
type apiServer struct {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/rancher/apiserver/pkg/types"
|
"github.com/rancher/apiserver/pkg/types"
|
||||||
"github.com/rancher/steve/pkg/attributes"
|
"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) {
|
func apiRoot(sf schema.Factory, apiOp *types.APIRequest) {
|
||||||
apiOp.Type = "apiRoot"
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user