diff --git a/client/src/helpers/constants.js b/client/src/helpers/constants.js index 0372fb95..3f3172b9 100644 --- a/client/src/helpers/constants.js +++ b/client/src/helpers/constants.js @@ -72,3 +72,4 @@ export const SETTINGS_NAMES = { }; export const STANDARD_DNS_PORT = 53; +export const STANDARD_WEB_PORT = 80; diff --git a/client/src/helpers/helpers.js b/client/src/helpers/helpers.js index ad6dcdca..0630416d 100644 --- a/client/src/helpers/helpers.js +++ b/client/src/helpers/helpers.js @@ -4,7 +4,7 @@ import subHours from 'date-fns/sub_hours'; import addHours from 'date-fns/add_hours'; import round from 'lodash/round'; -import { STATS_NAMES, STANDARD_DNS_PORT } from './constants'; +import { STATS_NAMES, STANDARD_DNS_PORT, STANDARD_WEB_PORT } from './constants'; export const formatTime = (time) => { const parsedTime = dateParse(time); @@ -111,20 +111,32 @@ export const getIpList = (interfaces) => { return list.sort(); }; -export const getAddress = (ip, port = '', isDns = false) => { - if (!port) { - return isDns ? ip : `http://${ip}`; - } +export const getDnsAddress = (ip, port = '') => { + const isStandardDnsPort = port === STANDARD_DNS_PORT; + let address = ip; - if (isDns) { - if (ip.includes(':') && port !== STANDARD_DNS_PORT) { - return `[${ip}]:${port}`; - } else if (port !== STANDARD_DNS_PORT) { - return `${ip}:${port}`; + if (port) { + if (ip.includes(':') && !isStandardDnsPort) { + address = `[${ip}]:${port}`; + } else if (!isStandardDnsPort) { + address = `${ip}:${port}`; } - - return ip; } - return ip.includes(':') ? `http://[${ip}]:${port}` : `http://${ip}:${port}`; + return address; +}; + +export const getWebAddress = (ip, port = '') => { + const isStandardWebPort = port === STANDARD_WEB_PORT; + let address = `http://${ip}`; + + if (port) { + if (ip.includes(':') && !isStandardWebPort) { + address = `http://[${ip}]:${port}`; + } else if (!isStandardWebPort) { + address = `http://${ip}:${port}`; + } + } + + return address; }; diff --git a/client/src/install/Setup/AddressList.js b/client/src/install/Setup/AddressList.js index 6654c2c4..425d6504 100644 --- a/client/src/install/Setup/AddressList.js +++ b/client/src/install/Setup/AddressList.js @@ -1,16 +1,16 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { getIpList, getAddress } from '../../helpers/helpers'; +import { getIpList, getDnsAddress, getWebAddress } from '../../helpers/helpers'; const AddressList = (props) => { - let webAddress = getAddress(props.address, props.port); - let dnsAddress = getAddress(props.address, props.port, true); + let webAddress = getWebAddress(props.address, props.port); + let dnsAddress = getDnsAddress(props.address, props.port); if (props.address === '0.0.0.0') { return getIpList(props.interfaces).map((ip) => { - webAddress = getAddress(ip, props.port); - dnsAddress = getAddress(ip, props.port, true); + webAddress = getWebAddress(ip, props.port); + dnsAddress = getDnsAddress(ip, props.port); if (props.isDns) { return ( diff --git a/client/src/install/Setup/Submit.js b/client/src/install/Setup/Submit.js index 23df3691..8456909a 100644 --- a/client/src/install/Setup/Submit.js +++ b/client/src/install/Setup/Submit.js @@ -6,7 +6,7 @@ import { Trans, withNamespaces } from 'react-i18next'; import flow from 'lodash/flow'; import Controls from './Controls'; -import { getAddress } from '../../helpers/helpers'; +import { getWebAddress } from '../../helpers/helpers'; let Submit = props => (