-
Notifications
You must be signed in to change notification settings - Fork 8
/
router.go
31 lines (24 loc) · 1.01 KB
/
router.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package server
import (
"net/http"
"github.com/cnrancher/edge-api-server/pkg/auth"
"github.com/cnrancher/edge-api-server/pkg/extendapi"
"github.com/cnrancher/edge-api-server/pkg/server/ui"
"github.com/gorilla/mux"
"github.com/rancher/apiserver/pkg/middleware"
)
func SetupLocalHandler(server *EdgeServer) http.Handler {
r := mux.NewRouter()
r.UseEncodedPath()
authHandler := auth.NewAuthHandler(server.Context, server.RestConfig.Host, server.ClientSet)
dataStorageHealthHandler := extendapi.NewDataStorgeHealthHandler(server.ClientSet)
r.Path("/").Handler(http.RedirectHandler("/dashboard", http.StatusTemporaryRedirect))
r.Path("/v2-public/auth").Handler(authHandler)
r.Path("/v2-public/health/datastorage").Handler(dataStorageHealthHandler)
//API UI
uiContent := middleware.NewMiddlewareChain(middleware.Gzip, middleware.DenyFrameOptions,
middleware.CacheMiddleware("json", "js", "css")).Handler(ui.Content())
r.PathPrefix("/api-ui").Handler(uiContent)
r.NotFoundHandler = http.NotFoundHandler()
return r
}