don't always assume old Dashboard is hosted with "/old" suffix. For third party packages that assumption can be wrong. Detect the suffix using document.currentScript, to allow backwards compatibility (#9814)
Jacek Kolasa committed
Aug 26, 2020 at 17:08 UTC
8ae4179ba3e1e34731cf841d5173877ea7eee136
1 file changed
+19
-5
web/gui/main.js
+19
-5
@@ -500,11 +500,25 @@ function toggleAgentItem(e, guid) {
500
// has multiple host databases. It's own, and multiple mirrored. Mirrored databases
501
// can be accessed with <http://localhost:19999/host/NAME/>
502
const OLD_DASHBOARD_SUFFIX = "old"
503
+let isOldSuffix = true
504
+try {
505
+ const currentScriptMainJs = document.currentScript;
506
+ const mainJsSrc = currentScriptMainJs.getAttribute("src")
507
+ isOldSuffix = mainJsSrc.startsWith("../main.js")
508
+} catch {
509
+ console.warn("current script not detecting, assuming the dashboard is running with /old suffix")
510
+}
511
+
512
+function transformWithOldSuffix(url) {
513
+ return isOldSuffix ? `../${url}` : url
514
+}
515
+
516
function renderStreamedHosts(options) {
517
let html = `<div class="info-item">Databases streamed to this agent</div>`;
518
519
var base = document.location.origin.toString() +
507
- document.location.pathname.toString().replace(`/${OLD_DASHBOARD_SUFFIX}`, "");
520
+ document.location.pathname.toString()
521
+ .replace(isOldSuffix ? `/${OLD_DASHBOARD_SUFFIX}` : "", "");
522
if (base.endsWith("/host/" + options.hostname + "/")) {
523
base = base.substring(0, base.length - ("/host/" + options.hostname + "/").toString().length);
524
}
@@ -538,10 +552,10 @@ function renderStreamedHosts(options) {
552
displayedDatabases = true;
553
554
if (hostname === master) {
541
- url = `${base}/${OLD_DASHBOARD_SUFFIX}/`;
555
+ url = isOldSuffix ? `${base}/${OLD_DASHBOARD_SUFFIX}/` : `${base}/`;
556
icon = 'home';
557
} else {
544
- url = `${base}/host/${hostname}/${OLD_DASHBOARD_SUFFIX}/`;
558
+ url = isOldSuffix ? `${base}/host/${hostname}/${OLD_DASHBOARD_SUFFIX}/` : `${base}/host/${hostname}/`;
559
icon = 'window-restore';
560
}
561
@@ -1929,7 +1943,7 @@ function renderChartsAndMenu(data) {
1943
1944
function loadJs(url, callback) {
1945
$.ajax({
1932
- url: url.startsWith("http") ? url : `../${url}`,
1946
+ url: url.startsWith("http") ? url : transformWithOldSuffix(url),
1947
cache: true,
1948
dataType: "script",
1949
xhrFields: { withCredentials: true } // required for the cookie
@@ -1976,7 +1990,7 @@ function loadBootstrapSlider(callback) {
1990
if (bootstrapSliderLoaded === false) {
1991
bootstrapSliderLoaded = true;
1992
loadJs('lib/bootstrap-slider-10.0.0.min.js', function () {
1979
- NETDATA._loadCSS('../css/bootstrap-slider-10.0.0.min.css');
1993
+ NETDATA._loadCSS(transformWithOldSuffix("css/bootstrap-slider-10.0.0.min.css"));
1994
callback();
1995
});
1996
} else {