MCPcopy Create free account
hub / github.com/couchbase/cbft / InitStaticRouter

Function InitStaticRouter

rest.go:32–93  ·  view source on GitHub ↗
(staticDir, staticETag string,
	mgr *cbgt.Manager)

Source from the content-addressed store, hash-verified

30}
31
32func InitStaticRouter(staticDir, staticETag string,
33 mgr *cbgt.Manager) *mux.Router {
34 router := mux.NewRouter()
35 router.StrictSlash(true)
36
37 showUI := true
38 if mgr != nil && mgr.Options()["hideUI"] != "" {
39 hideUI, err := strconv.ParseBool(mgr.Options()["hideUI"])
40 if err == nil && hideUI {
41 showUI = false
42 }
43 }
44
45 if showUI {
46 prefix := ""
47 if mgr != nil {
48 prefix = mgr.Options()["urlPrefix"]
49 }
50
51 hfsStaticX := http.FileServer(assetFS())
52
53 router.Handle(prefix+"/",
54 http.RedirectHandler(prefix+"/index.html", 302))
55 router.Handle(prefix+"/index.html",
56 http.RedirectHandler(prefix+"/staticx/index.html", 302))
57 router.Handle(prefix+"/static/partials/index/start.html",
58 http.RedirectHandler(prefix+"/staticx/partials/index/start.html", 302))
59 router.Handle(prefix+"/static/partials/index/new.html",
60 http.RedirectHandler(prefix+"/staticx/partials/index/ft/new.html", 302))
61 router.Handle(prefix+"/static/partials/index/list.html",
62 http.RedirectHandler(prefix+"/staticx/partials/index/ft/list.html", 302))
63
64 router = rest.InitStaticRouterEx(router,
65 staticDir, staticETag, []string{
66 prefix + "/indexes",
67 prefix + "/nodes",
68 prefix + "/monitor",
69 prefix + "/manage",
70 prefix + "/logs",
71 prefix + "/debug",
72 }, http.RedirectHandler(prefix+"/staticx/index.html", 302), mgr)
73
74 staticxRoutes := []string{
75 "/staticx/",
76 "/staticx/css/cbft.css",
77 "/staticx/index.html",
78 "/staticx/index-ft.html",
79 "/staticx/js/debug.js",
80 "/staticx/partials/debug-rows.html",
81 "/staticx/partials/debug.html",
82 "/staticx/partials/index/ft/list.html",
83 "/staticx/partials/index/ft/new.html",
84 "/staticx/partials/index/start.html",
85 }
86
87 for _, route := range staticxRoutes {
88 router.Handle(prefix+route, http.StripPrefix(prefix+"/staticx/", hfsStaticX))
89 }

Callers 1

NewRESTRouterFunction · 0.85

Calls 1

assetFSFunction · 0.85

Tested by

no test coverage detected