From 0209c6e0ff3b8ab95456397a14d911b465a34916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 27 Jul 2017 17:35:05 +0200 Subject: [PATCH] Fix connecting to wildcard addresses. (#6167) --- js/src/secureApi.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/js/src/secureApi.js b/js/src/secureApi.js index b539f3ece..c34f71dd9 100644 --- a/js/src/secureApi.js +++ b/js/src/secureApi.js @@ -101,13 +101,7 @@ export default class SecureApi extends Api { return 'dapps.parity'; } - const { host } = this._dappsAddress; - - if (!host || host === '0.0.0.0') { - return window.location.hostname; - } - - return host; + return this._dappsAddress.host; } get isConnecting () { @@ -173,6 +167,25 @@ export default class SecureApi extends Api { }); } + /** + * Resolves a wildcard address to `window.location.hostname`; + */ + _resolveHost (url) { + const parts = url ? url.split(':') : []; + const port = parts[1]; + let host = parts[0]; + + if (!host) { + return host; + } + + if (host === '0.0.0.0') { + host = window.location.hostname; + } + + return port ? `${host}:${port}` : host; + } + /** * Returns a Promise that gets resolved with * a boolean: `true` if the node is up, `false` @@ -316,8 +329,8 @@ export default class SecureApi extends Api { this._uiApi.parity.wsUrl() ]) .then(([dappsUrl, wsUrl]) => { - this._dappsUrl = dappsUrl; - this._wsUrl = wsUrl; + this._dappsUrl = this._resolveHost(dappsUrl); + this._wsUrl = this._resolveHost(wsUrl); }); }