Skip to content

Commit 863c771

Browse files
authored
Fixing BasePath for loading static assets and routing when a URL doesn't have a forward slash suffix (#713)
* Remove suffix trimming on BasePath * Remove forward-slash prefix for static images in html templates * Allow for routing on base URLs missing a forward-slash suffix * Move rootURL routing functionality to new method, modify its if statement, trim suffix for router's PathPrefix, move opts to a class-wide variable, add a new Handler for rootURLs without the forward slash * Reverted previous commit aside from trimming the suffix of the BasePath in the router builder, added StrictSlash(true) to the router builder * Reformatted router.go
1 parent 0d0c0fb commit 863c771

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

cmd/dashboard.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,9 @@ func validateBasePath(path string) string {
7575
path = "/" + path
7676
}
7777

78-
return strings.TrimSuffix(path, "/")
78+
if !strings.HasSuffix(path, "/") {
79+
path = path + "/"
80+
}
81+
82+
return path
7983
}

pkg/dashboard/router.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package dashboard
1717
import (
1818
"net/http"
1919
"path"
20+
"strings"
2021

2122
"k8s.io/klog/v2"
2223

@@ -50,7 +51,7 @@ func GetRouter(setters ...Option) *mux.Router {
5051
setter(opts)
5152
}
5253

53-
router := mux.NewRouter().PathPrefix(opts.BasePath).Subrouter()
54+
router := mux.NewRouter().PathPrefix(strings.TrimSuffix(opts.BasePath, "/")).Subrouter().StrictSlash(true)
5455

5556
// health
5657
router.Handle("/health", Health("OK"))

pkg/dashboard/templates/cost_settings.gohtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
<div class="cost-settings-box__select-container">
1414
<select name="cloud-providers" id="cost-settings-box__cloud-providers">
1515
</select>
16-
<img src="/static/images/triangle.svg" alt="Select Icon" aria-hidden="true" />
16+
<img src="static/images/triangle.svg" alt="Select Icon" aria-hidden="true" />
1717
</div>
1818
</div>
1919
<div class="cost-settings-box__instance-types">
2020
<label for="cost-settings-box__instance-types">Instance Type</label>
2121
<div class="cost-settings-box__select-container">
2222
<select name="instance-types" id="cost-settings-box__instance-types">
2323
</select>
24-
<img src="/static/images/triangle.svg" alt="Select Icon" aria-hidden="true" />
24+
<img src="static/images/triangle.svg" alt="Select Icon" aria-hidden="true" />
2525
</div>
2626
</div>
2727
</div>

pkg/dashboard/templates/footer.gohtml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
</div>
66
<div class="footer__middle">
77
<a href="https://github.com/FairwindsOps">
8-
<img src="/static/images/github.svg" alt="Github" />
8+
<img src="static/images/github.svg" alt="Github" />
99
</a>
1010
<a href="https://twitter.com/fairwindsops">
11-
<img src="/static/images/twitter.svg" alt="Twitter" />
11+
<img src="static/images/twitter.svg" alt="Twitter" />
1212
</a>
1313
<a href="https://join.slack.com/t/fairwindscommunity/shared_invite/zt-e3c6vj4l-3lIH6dvKqzWII5fSSFDi1g">
14-
<img src="/static/images/slack.svg" alt="Slack" />
14+
<img src="static/images/slack.svg" alt="Slack" />
1515
</a>
1616
<a href="https://www.fairwinds.com/fairwinds-newsletter">
17-
<img src="/static/images/email.svg" alt="Email" />
17+
<img src="static/images/email.svg" alt="Email" />
1818
</a>
1919
</div>
2020
<div class="footer__logo">
2121
<a href="https://fairwinds.com">
22-
<img src="/static/images/fairwinds-logo.svg" alt="Fairwinds Logo" />
22+
<img src="static/images/fairwinds-logo.svg" alt="Fairwinds Logo" />
2323
</a>
2424
</div>
2525
<div class="footer__bottom">

0 commit comments

Comments
 (0)