Remove hardcoded url & use absolute url to make requests

This commit is contained in:
Jannis Mattheis 2018-03-18 16:03:53 +01:00 committed by Jannis Mattheis
parent 1e33fd0ea4
commit d931dfc696
2 changed files with 9 additions and 4 deletions

View File

@ -38,8 +38,8 @@ export function listenToWebSocket() {
if (!getToken()) { if (!getToken()) {
return; return;
} }
const wsUrl = config.get('url').replace('http', 'ws').replace('https', 'wss');
const ws = new WebSocket('ws://localhost:80/stream?token=' + getToken()); const ws = new WebSocket(wsUrl + 'stream?token=' + getToken());
ws.onerror = (e) => { ws.onerror = (e) => {
console.log('WebSocket connection errored; trying again in 60 seconds', e); console.log('WebSocket connection errored; trying again in 60 seconds', e);

View File

@ -11,8 +11,13 @@ const defaultDevConfig = {
url: 'http://localhost:80/', 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 = { const defaultProdConfig = {
url: './', url: urlWithSlash,
}; };
(function clientJS() { (function clientJS() {