Check if redirect is available before enable
This commit is contained in:
parent
9d4b829fb6
commit
a60eeb55f1
|
@ -73,6 +73,7 @@ export const SETTINGS_NAMES = {
|
||||||
|
|
||||||
export const STANDARD_DNS_PORT = 53;
|
export const STANDARD_DNS_PORT = 53;
|
||||||
export const STANDARD_WEB_PORT = 80;
|
export const STANDARD_WEB_PORT = 80;
|
||||||
|
export const STANDARD_HTTPS_PORT = 443;
|
||||||
|
|
||||||
export const EMPTY_DATE = '0001-01-01T00:00:00Z';
|
export const EMPTY_DATE = '0001-01-01T00:00:00Z';
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,13 @@ import dateFormat from 'date-fns/format';
|
||||||
import subHours from 'date-fns/sub_hours';
|
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 axios from 'axios';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
STATS_NAMES,
|
STATS_NAMES,
|
||||||
STANDARD_DNS_PORT,
|
STANDARD_DNS_PORT,
|
||||||
STANDARD_WEB_PORT,
|
STANDARD_WEB_PORT,
|
||||||
|
STANDARD_HTTPS_PORT,
|
||||||
CHECK_TIMEOUT,
|
CHECK_TIMEOUT,
|
||||||
STOP_TIMEOUT,
|
STOP_TIMEOUT,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
|
@ -147,31 +149,39 @@ export const getWebAddress = (ip, port = '') => {
|
||||||
return address;
|
return address;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const redirectCheck = (url) => {
|
||||||
|
const redirectCheck = setInterval(() => {
|
||||||
|
axios.get(url)
|
||||||
|
.then((response) => {
|
||||||
|
if (response) {
|
||||||
|
clearInterval(redirectCheck);
|
||||||
|
window.location.replace(url);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
if (error.response) {
|
||||||
|
clearInterval(redirectCheck);
|
||||||
|
window.location.replace(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, CHECK_TIMEOUT);
|
||||||
|
setTimeout(() => {
|
||||||
|
clearInterval(redirectCheck);
|
||||||
|
console.error('Redirect check stopped');
|
||||||
|
}, STOP_TIMEOUT);
|
||||||
|
};
|
||||||
|
|
||||||
export const redirectToCurrentProtocol = (values) => {
|
export const redirectToCurrentProtocol = (values) => {
|
||||||
const {
|
const {
|
||||||
protocol, hostname, hash, port,
|
protocol, hostname, hash, port,
|
||||||
} = window.location;
|
} = window.location;
|
||||||
const { enabled, port_https } = values;
|
const { enabled, port_https } = values;
|
||||||
const httpsPort = port_https !== 443 ? `:${port_https}` : '';
|
const httpsPort = port_https !== STANDARD_HTTPS_PORT ? `:${port_https}` : '';
|
||||||
|
|
||||||
if (protocol !== 'https:' && enabled && port_https) {
|
if (protocol !== 'https:' && enabled && port_https) {
|
||||||
window.location.replace(`https://${hostname}${httpsPort}/${hash}`);
|
redirectCheck(`https://${hostname}${httpsPort}/${hash}`);
|
||||||
} else if (protocol === 'https:' && enabled && port_https && port_https !== port) {
|
} else if (protocol === 'https:' && enabled && port_https && port_https !== port) {
|
||||||
// TODO
|
redirectCheck(`https://${hostname}${httpsPort}/${hash}`);
|
||||||
const redirectCheck = setInterval(() => {
|
|
||||||
fetch(`https://${hostname}${httpsPort}/${hash}`, { mode: 'no-cors' })
|
|
||||||
.then((response) => {
|
|
||||||
if (response) {
|
|
||||||
clearInterval(redirectCheck);
|
|
||||||
window.location.replace(`https://${hostname}${httpsPort}/${hash}`);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => false);
|
|
||||||
}, CHECK_TIMEOUT);
|
|
||||||
setTimeout(() => {
|
|
||||||
clearInterval(redirectCheck);
|
|
||||||
console.error('Redirect check stopped');
|
|
||||||
}, STOP_TIMEOUT);
|
|
||||||
} else if (protocol === 'https:' && (!enabled || !port_https)) {
|
} else if (protocol === 'https:' && (!enabled || !port_https)) {
|
||||||
window.location.replace(`http://${hostname}/${hash}`);
|
window.location.replace(`http://${hostname}/${hash}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue