From c28e63c65c60df8b44fbcaca3fe5f892499cde40 Mon Sep 17 00:00:00 2001 From: Aleksey Popov Date: Fri, 16 Jun 2017 00:39:40 +0300 Subject: [PATCH] Use 'a' element to parse url instead of Regexp --- src/services/api/peers.js | 9 +++++---- src/util/urlParser.js | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 src/util/urlParser.js diff --git a/src/services/api/peers.js b/src/services/api/peers.js index 20705896c..19784f657 100644 --- a/src/services/api/peers.js +++ b/src/services/api/peers.js @@ -1,5 +1,5 @@ import lisk from 'lisk-js'; - +import urlParser from '../../util/urlParser'; /** * This factory provides methods for communicating with peers. It exposes * sendRequestPromise method for requesting to available endpoint to the active peer, @@ -54,9 +54,10 @@ app.factory('Peers', ($timeout, $cookies, $location, $q, $rootScope, dialog) => if (network) { conf = network; if (network.address) { - conf.node = network.address.split(':')[1].replace('//', ''); - conf.port = network.address.match(/:([0-9]{1,5})\/?$/) && network.address.match(/:([0-9]{1,5})\/?$/)[1]; - conf.ssl = network.address.split(':')[0] === 'https'; + const { hostname, port, protocol } = urlParser(network.address); + conf.node = hostname; + conf.port = port; + conf.ssl = protocol === 'https:'; } if (conf.testnet === undefined && conf.port !== undefined) { conf.testnet = conf.port === '7000'; diff --git a/src/util/urlParser.js b/src/util/urlParser.js new file mode 100644 index 000000000..f55216052 --- /dev/null +++ b/src/util/urlParser.js @@ -0,0 +1,6 @@ +export default function (url) { + const link = document.createElement('a'); + link.href = url; + return link; +} +