Remove hardcoded websocket host

This commit is contained in:
Gabe Kangas
2022-10-09 21:16:46 -07:00
parent de87b78768
commit 8f0541a0f1

View File

@@ -37,7 +37,10 @@ export default class WebsocketService {
} }
createAndConnect() { createAndConnect() {
const url = new URL('ws://localhost:8080/ws'); const url = new URL(window.location.toString());
url.protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
url.pathname = '/ws';
url.port = window.location.port === '3000' ? '8080' : window.location.port;
url.searchParams.append('accessToken', this.accessToken); url.searchParams.append('accessToken', this.accessToken);
console.debug('connecting to ', url.toString()); console.debug('connecting to ', url.toString());
@@ -84,8 +87,8 @@ export default class WebsocketService {
if (this.handleMessage) { if (this.handleMessage) {
this.handleMessage(socketEvent); this.handleMessage(socketEvent);
} }
} catch (e) { } catch (err) {
console.error(e, e.data); console.error(err, err.data);
return; return;
} }