Skip to content

Commit eee7dfd

Browse files
giladgdgregberge
authored andcommitted
Fix an error that being logged in the console when Webpack is using WebSocket and not SockJS
1 parent 8aa4edf commit eee7dfd

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/entries/devserver.mjs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@ if (typeof __resourceQuery === 'string' && __resourceQuery) {
1010
sockOptions = querystring.parse(__resourceQuery.substr(1))
1111
}
1212

13-
const connection = new SockJS(
14-
`${window.location.protocol}//${
15-
sockOptions.sockHost || window.location.hostname
16-
}:${sockOptions.sockPort || window.location.port}${
17-
sockOptions.sockPath || '/sockjs-node'
18-
}`,
19-
)
13+
const connection =
14+
sockOptions.sockPath === '/ws' && typeof WebSocket !== 'undefined'
15+
? new WebSocket(
16+
`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${
17+
sockOptions.sockHost || window.location.hostname
18+
}:${sockOptions.sockPort || window.location.port}${
19+
sockOptions.sockPath || '/ws'
20+
}`,
21+
)
22+
: new SockJS(
23+
`${window.location.protocol}//${
24+
sockOptions.sockHost || window.location.hostname
25+
}:${sockOptions.sockPort || window.location.port}${
26+
sockOptions.sockPath || '/sockjs-node'
27+
}`,
28+
)
2029

2130
connection.onmessage = function onmessage(e) {
2231
const { type, data } = JSON.parse(e.data)

0 commit comments

Comments
 (0)