Skip to content

Commit

Permalink
Merge branch 'release-4.0' into cherry-pick-3712-to-release-4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jul 6, 2021
2 parents 561eadc + 4a50ce9 commit 852a4d2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
"context"
"net/http"
"net/http/pprof"
"strings"

"github.com/gorilla/mux"
"github.com/pingcap/failpoint"
"github.com/tikv/pd/server"
"github.com/unrolled/render"
)
Expand Down Expand Up @@ -51,7 +53,8 @@ func createRouter(ctx context.Context, prefix string, svr *server.Server) *mux.R
rootRouter := mux.NewRouter().PathPrefix(prefix).Subrouter()
handler := svr.GetHandler()

apiRouter := rootRouter.PathPrefix("/api/v1").Subrouter()
apiPrefix := "/api/v1"
apiRouter := rootRouter.PathPrefix(apiPrefix).Subrouter()

clusterRouter := apiRouter.NewRoute().Subrouter()
clusterRouter.Use(newClusterMiddleware(svr).Middleware)
Expand Down Expand Up @@ -211,6 +214,15 @@ func createRouter(ctx context.Context, prefix string, svr *server.Server) *mux.R
apiRouter.HandleFunc("/gc/safepoint", serviceGCSafepointHandler.List).Methods("GET")
apiRouter.HandleFunc("/gc/safepoint/{service_id}", serviceGCSafepointHandler.Delete).Methods("DELETE")

// API to set or unset failpoints
failpoint.Inject("enableFailpointAPI", func() {
apiRouter.PathPrefix("/fail").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// The HTTP handler of failpoint requires the full path to be the failpoint path.
r.URL.Path = strings.TrimPrefix(r.URL.Path, prefix+apiPrefix+"/fail")
new(failpoint.HttpHandler).ServeHTTP(w, r)
})
})

// Deprecated
rootRouter.Handle("/health", newHealthHandler(svr, rd)).Methods("GET")
// Deprecated
Expand Down

0 comments on commit 852a4d2

Please sign in to comment.