Skip to content

Commit 738af04

Browse files
narkqSpaceK33z
authored andcommitted
Avoid accessing document if __resourceQuery is defined (#577)
1 parent 97ef7b5 commit 738af04

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

client/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
var url = require('url');
22
var SockJS = require("sockjs-client");
33
var stripAnsi = require('strip-ansi');
4-
var scriptElements = document.getElementsByTagName("script");
5-
var scriptHost = scriptElements[scriptElements.length-1].getAttribute("src").replace(/\/[^\/]+$/, "");
64

75
// If this bundle is inlined, use the resource query to get the correct url.
86
// Else, get the url from the <script> this file was called with.
9-
var urlParts = url.parse(typeof __resourceQuery === "string" && __resourceQuery ?
10-
__resourceQuery.substr(1) :
11-
(scriptHost ? scriptHost : "/"), false, true
12-
);
7+
var urlParts;
8+
if (typeof __resourceQuery === "string" && __resourceQuery) {
9+
urlParts = url.parse(__resourceQuery.substr(1));
10+
} else {
11+
var scriptElements = document.getElementsByTagName("script");
12+
urlParts = url.parse(scriptElements[scriptElements.length-1].getAttribute("src").replace(/\/[^\/]+$/, ""))
13+
}
1314

1415
var sock = null;
1516
var hot = false;

0 commit comments

Comments
 (0)