diff --git a/ui/src/actions/MessageAction.js b/ui/src/actions/MessageAction.js
index 2f93941..4ad831f 100644
--- a/ui/src/actions/MessageAction.js
+++ b/ui/src/actions/MessageAction.js
@@ -38,8 +38,8 @@ export function listenToWebSocket() {
if (!getToken()) {
return;
}
-
- const ws = new WebSocket('ws://localhost:80/stream?token=' + getToken());
+ const wsUrl = config.get('url').replace('http', 'ws').replace('https', 'wss');
+ const ws = new WebSocket(wsUrl + 'stream?token=' + getToken());
ws.onerror = (e) => {
console.log('WebSocket connection errored; trying again in 60 seconds', e);
diff --git a/ui/src/index.js b/ui/src/index.js
index 5087004..8ee14a5 100644
--- a/ui/src/index.js
+++ b/ui/src/index.js
@@ -11,8 +11,13 @@ const defaultDevConfig = {
url: 'http://localhost:80/',
};
+const {port, hostname, protocol} = window.location;
+const slashes = protocol.concat('//');
+const url = slashes.concat(hostname.concat(':', port));
+const urlWithSlash = url.endsWith('/') ? url : url.concat('/');
+
const defaultProdConfig = {
- url: './',
+ url: urlWithSlash,
};
(function clientJS() {
@@ -22,6 +27,6 @@ const defaultProdConfig = {
config.set(window.config || defaultDevConfig);
}
checkIfAlreadyLoggedIn();
- ReactDOM.render(, document.getElementById('root'));
+ ReactDOM.render(, document.getElementById('root'));
registerServiceWorker();
}());