mirror of https://github.com/linkerd/linkerd2.git
Include path prefix in location of js asset bundle (#959)
Problem If you navigate directly to (or do a hard refresh on) a path with more than one segment, e.g. http://localhost:8084/namespaces/conduit, the dashboard js is not served. Pages with two paths have to be accessed by loading the dashboard on a different path and then clicking through. When accessing the dashboard via conduit dashboard we append a path prefix so that we can connect using the k8s proxy. This means that moving the dashboard to serve images off relative paths won't work, because we need to serve images whether the dashboard is loaded from http://localhost:8084/namespaces/conduit or from http://localhost:8084/namespaces. Solution Check whether we're serving the dashboard with the proxy url, and if we are, adjust the url at which we serve the index bundle from. I've also added a very manual override if the conduit logo can't be found at the usual url.
This commit is contained in:
parent
fbba6bf4c8
commit
1464470487
|
@ -83,7 +83,14 @@ export default class Sidebar extends React.Component {
|
|||
<div className="sidebar">
|
||||
|
||||
<div className={`sidebar-menu-header ${this.state.collapsed ? "collapsed" : ""}`}>
|
||||
<ConduitLink to="/servicemesh"><img src={this.state.collapsed ? logo : wordLogo} /></ConduitLink>
|
||||
<ConduitLink to="/servicemesh">
|
||||
<img
|
||||
src={this.state.collapsed ? logo : wordLogo}
|
||||
onError={e => {
|
||||
// awful hack to deal with the fact that we don't serve assets off absolute paths
|
||||
e.target.src = e.target.src.replace(/(.*)(\/[a-zA-Z]*)(\/dist)(.*)/, "$1$3$4");
|
||||
}} />
|
||||
</ConduitLink>
|
||||
</div>
|
||||
|
||||
<Menu
|
||||
|
|
|
@ -2,12 +2,15 @@ package srv
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"regexp"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
pb "github.com/runconduit/conduit/controller/gen/public"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var proxyPathRegexp = regexp.MustCompile("/api/v1/namespaces/.*/proxy/")
|
||||
|
||||
type (
|
||||
renderTemplate func(http.ResponseWriter, string, string, interface{}) error
|
||||
serveFile func(http.ResponseWriter, string, string, interface{}) error
|
||||
|
@ -22,7 +25,17 @@ type (
|
|||
)
|
||||
|
||||
func (h *handler) handleIndex(w http.ResponseWriter, req *http.Request, p httprouter.Params) {
|
||||
params := appParams{UUID: h.uuid, ControllerNamespace: h.controllerNamespace}
|
||||
// when running the dashboard via `conduit dashboard`, serve the index bundle at the right path
|
||||
pathPfx := proxyPathRegexp.FindString(req.URL.Path)
|
||||
if pathPfx == "" {
|
||||
pathPfx = "/"
|
||||
}
|
||||
|
||||
params := appParams{
|
||||
UUID: h.uuid,
|
||||
ControllerNamespace: h.controllerNamespace,
|
||||
PathPrefix: pathPfx,
|
||||
}
|
||||
|
||||
version, err := h.apiClient.Version(req.Context(), &pb.Empty{}) // TODO: remove and call /api/version from web app
|
||||
if err != nil {
|
||||
|
|
|
@ -42,6 +42,7 @@ type (
|
|||
ControllerNamespace string
|
||||
Error bool
|
||||
ErrorMessage string
|
||||
PathPrefix string
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -11,11 +11,9 @@
|
|||
{{ end }}
|
||||
|
||||
{{ define "script-tags" }}
|
||||
{{with .Context}}
|
||||
{{ if .WebpackDevServer}}
|
||||
<script type="text/javascript" src="{{.WebpackDevServer}}/dist/index_bundle.js" async></script>
|
||||
{{ if .Context.WebpackDevServer }}
|
||||
<script type="text/javascript" src="{{.Context.WebpackDevServer}}/dist/index_bundle.js" async></script>
|
||||
{{else}}
|
||||
<script type="text/javascript" src="dist/index_bundle.js" async></script>
|
||||
{{end}}
|
||||
<script type="text/javascript" src="{{.Contents.PathPrefix}}dist/index_bundle.js" async></script>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
|
Loading…
Reference in New Issue