Open websocket on same path as page (#149)

This is the critical piece to let you serve code-server proxied under a
path.  Otherwise if you proxy e.g. `/editor/` thru to
`http://localhost:8000`, everything works fine except the websocket
connection is still opened to `/`
This commit is contained in:
David Bushong 2019-03-09 09:23:51 -08:00 committed by Kyle Carberry
parent 30d14eeab4
commit d7a66e4f15
1 changed files with 2 additions and 1 deletions

View File

@ -91,8 +91,9 @@ class WebsocketConnection implements ReadWriteConnection {
*/
private async openSocket(): Promise<WebSocket> {
this.dispose();
const wsProto = location.protocol === "https:" ? "wss" : "ws";
const socket = new WebSocket(
`${location.protocol === "https:" ? "wss" : "ws"}://${location.host}`,
`${wsProto}://${location.host}${location.pathname}`,
);
socket.binaryType = "arraybuffer";
this.activeSocket = socket;