Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Use <a> element to parse url instead of Regexp #418

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/services/api/peers.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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';
Expand Down
6 changes: 6 additions & 0 deletions src/util/urlParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function (url) {
const link = document.createElement('a');
link.href = url;
return link;
}