Hide 80 web port

This commit is contained in:
Ildar Kamalov 2019-02-06 17:32:32 +03:00
parent 672ff33879
commit ba678ffa82
4 changed files with 33 additions and 20 deletions

View File

@ -72,3 +72,4 @@ export const SETTINGS_NAMES = {
}; };
export const STANDARD_DNS_PORT = 53; export const STANDARD_DNS_PORT = 53;
export const STANDARD_WEB_PORT = 80;

View File

@ -4,7 +4,7 @@ import subHours from 'date-fns/sub_hours';
import addHours from 'date-fns/add_hours'; import addHours from 'date-fns/add_hours';
import round from 'lodash/round'; 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) => { export const formatTime = (time) => {
const parsedTime = dateParse(time); const parsedTime = dateParse(time);
@ -111,20 +111,32 @@ export const getIpList = (interfaces) => {
return list.sort(); return list.sort();
}; };
export const getAddress = (ip, port = '', isDns = false) => { export const getDnsAddress = (ip, port = '') => {
if (!port) { const isStandardDnsPort = port === STANDARD_DNS_PORT;
return isDns ? ip : `http://${ip}`; let address = ip;
if (port) {
if (ip.includes(':') && !isStandardDnsPort) {
address = `[${ip}]:${port}`;
} else if (!isStandardDnsPort) {
address = `${ip}:${port}`;
}
} }
if (isDns) { return address;
if (ip.includes(':') && port !== STANDARD_DNS_PORT) { };
return `[${ip}]:${port}`;
} else if (port !== STANDARD_DNS_PORT) { export const getWebAddress = (ip, port = '') => {
return `${ip}:${port}`; const isStandardWebPort = port === STANDARD_WEB_PORT;
} let address = `http://${ip}`;
return ip; if (port) {
} if (ip.includes(':') && !isStandardWebPort) {
address = `http://[${ip}]:${port}`;
return ip.includes(':') ? `http://[${ip}]:${port}` : `http://${ip}:${port}`; } else if (!isStandardWebPort) {
address = `http://${ip}:${port}`;
}
}
return address;
}; };

View File

@ -1,16 +1,16 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { getIpList, getAddress } from '../../helpers/helpers'; import { getIpList, getDnsAddress, getWebAddress } from '../../helpers/helpers';
const AddressList = (props) => { const AddressList = (props) => {
let webAddress = getAddress(props.address, props.port); let webAddress = getWebAddress(props.address, props.port);
let dnsAddress = getAddress(props.address, props.port, true); let dnsAddress = getDnsAddress(props.address, props.port);
if (props.address === '0.0.0.0') { if (props.address === '0.0.0.0') {
return getIpList(props.interfaces).map((ip) => { return getIpList(props.interfaces).map((ip) => {
webAddress = getAddress(ip, props.port); webAddress = getWebAddress(ip, props.port);
dnsAddress = getAddress(ip, props.port, true); dnsAddress = getDnsAddress(ip, props.port);
if (props.isDns) { if (props.isDns) {
return ( return (

View File

@ -6,7 +6,7 @@ import { Trans, withNamespaces } from 'react-i18next';
import flow from 'lodash/flow'; import flow from 'lodash/flow';
import Controls from './Controls'; import Controls from './Controls';
import { getAddress } from '../../helpers/helpers'; import { getWebAddress } from '../../helpers/helpers';
let Submit = props => ( let Submit = props => (
<div className="setup__step"> <div className="setup__step">
@ -20,7 +20,7 @@ let Submit = props => (
</div> </div>
<Controls <Controls
openDashboard={props.openDashboard} openDashboard={props.openDashboard}
address={getAddress(props.webIp, props.webPort)} address={getWebAddress(props.webIp, props.webPort)}
/> />
</div> </div>
); );