Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit db5c1eb

Browse files
committed
use exact environment baseURL
1 parent c4a5e24 commit db5c1eb

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/system.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,34 @@
8585
var SystemLoader = function(options) {
8686
Loader.call(this, options || {});
8787

88+
var baseURL;
8889
// Set default baseURL and paths
89-
if (typeof location != 'undefined' && location.href) {
90-
var href = __global.location.href.split('#')[0].split('?')[0];
91-
this.baseURL = href.substring(0, href.lastIndexOf('/') + 1);
90+
if (isWorker) {
91+
baseURL = __global.location.href;
92+
}
93+
else if (typeof document != 'undefined') {
94+
baseURL = document.baseURI;
95+
96+
if (!baseURL) {
97+
var bases = document.getElementsByTagName('base');
98+
baseURL = bases[0] && bases[0].href || window.location.href;
99+
}
100+
101+
// sanitize out the hash and querystring
102+
// removes the username and password, which could be adjusted
103+
baseURL = new URL(baseURL);
104+
baseURL = baseURL.origin + baseURL.pathname.substr(0, baseURL.pathname.lastIndexOf('/') + 1);
92105
}
93106
else if (typeof process != 'undefined' && process.cwd) {
94-
this.baseURL = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
107+
baseURL = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
95108
if (isWindows)
96-
this.baseURL = this.baseURL.replace(/\\/g, '/');
109+
baseURL = baseURL.replace(/\\/g, '/');
97110
}
98111
else {
99112
throw new TypeError('No environment baseURL');
100113
}
114+
115+
this.baseURL = baseURL;
101116
this.paths = {};
102117
};
103118

0 commit comments

Comments
 (0)