@cryptotaxi247 / netdata-1 / commits / cb632c1b0

fix when netdata is proxies in a sub-directory #44

Costa Tsaousis (ktsaou) committed Jan 22, 2016 at 21:15 UTC cb632c1b06dc07648947b51de755550a8bef2d8e
1 file changed +10 -21
web/dashboard.js
+10 -21
@@ -29,8 +29,8 @@
29
30 // http://stackoverflow.com/questions/984510/what-is-my-script-src-url
31 // http://stackoverflow.com/questions/6941533/get-protocol-domain-and-port-from-url
32 - NETDATA._scriptSource = function(scripts) {
33 - var script = null, base = null;
32 + NETDATA._scriptSource = function() {
33 + var script = null;
34
35 if(typeof document.currentScript !== 'undefined') {
36 script = document.currentScript;
@@ -45,25 +45,15 @@
45 else
46 script = script.getAttribute('src', -1);
47
48 - var link = document.createElement('a');
49 - link.setAttribute('href', script);
50 -
51 - if(!link.protocol || !link.hostname) return null;
52 -
53 - base = link.protocol;
54 - if(base) base += "//";
55 - base += link.hostname;
56 -
57 - if(link.port) base += ":" + link.port;
58 - base += "/";
59 -
60 - return base;
48 + return script;
49 };
50
51 if(typeof netdataServer !== 'undefined')
52 NETDATA.serverDefault = netdataServer;
65 - else
66 - NETDATA.serverDefault = NETDATA._scriptSource();
53 + else {
54 + var s = NETDATA._scriptSource();
55 + NETDATA.serverDefault = s.replace(/\/dashboard.js(\?.*)*$/g, "");
56 + }
57
58 if(NETDATA.serverDefault === null)
59 NETDATA.serverDefault = '';
@@ -2286,7 +2276,7 @@
2276 this.data_points = this.points || Math.round(this.chartWidth() / this.chartPixelsPerPoint());
2277
2278 // build the data URL
2289 - this.data_url = this.chart.data_url;
2279 + this.data_url = this.host + this.chart.data_url;
2280 this.data_url += "&format=" + this.library.format();
2281 this.data_url += "&points=" + (this.data_points * points_multiplier).toString();
2282 this.data_url += "&group=" + this.method;
@@ -2669,20 +2659,19 @@
2659 if(typeof callback === 'function') callback();
2660 }
2661 else {
2672 - this.chart_url = this.host + "/api/v1/chart?chart=" + this.id;
2662 + this.chart_url = "/api/v1/chart?chart=" + this.id;
2663
2664 if(this.debug === true)
2665 this.log('downloading ' + this.chart_url);
2666
2667 $.ajax( {
2678 - url: this.chart_url,
2668 + url: this.host + this.chart_url,
2669 crossDomain: NETDATA.options.crossDomainAjax,
2670 cache: false,
2671 async: true
2672 })
2673 .done(function(chart) {
2674 chart.url = that.chart_url;
2685 - chart.data_url = (that.host + chart.data_url);
2675 that._defaultsFromDownloadedChart(chart);
2676 NETDATA.chartRegistry.add(that.host, that.id, chart);
2677 })