@@ -123,11 +123,31 @@ function showErrorOverlay(message) {
123
123
} ) ;
124
124
}
125
125
126
+ function getCurrentScriptSource ( ) {
127
+ // `document.currentScript` is the most accurate way to find the current script,
128
+ // but is not supported in all browsers.
129
+ if ( document . currentScript )
130
+ return document . currentScript . getAttribute ( "src" ) ;
131
+ // Fall back to getting all scripts in the document.
132
+ var scriptElements = document . scripts || [ ] ;
133
+ var currentScript = scriptElements [ scriptElements . length - 1 ] ;
134
+ if ( currentScript )
135
+ return currentScript . getAttribute ( "src" ) ;
136
+ }
137
+
138
+
139
+ var scriptHost = getCurrentScriptSource ( ) ;
140
+ scriptHost = scriptHost . replace ( / \/ [ ^ \/ ] + $ / , "" ) ;
141
+
142
+ var urlParts = url . parse ( ( scriptHost ? scriptHost : "/" ) , false , true ) ;
143
+ var hostname = urlParts . hostname ;
144
+ var protocol = urlParts . protocol ;
145
+
126
146
// Connect to WebpackDevServer via a socket.
127
147
var connection = new SockJS ( url . format ( {
128
- protocol : window . location . protocol ,
129
- hostname : window . location . hostname ,
130
- port : window . location . port ,
148
+ protocol : protocol ,
149
+ hostname : hostname ,
150
+ port : ( urlParts . port === "0" ) ? window . location . port : urlParts . port ,
131
151
// Hardcoded in WebpackDevServer
132
152
pathname : '/sockjs-node'
133
153
} ) ) ;
0 commit comments