Skip to content
Snippets Groups Projects
Unverified Commit cc1e17b1 authored by Jed Fox's avatar Jed Fox
Browse files

Auto-add https: protocol, and prompt to add http:// if that doesn’t work

parent 9abe7fa2
No related branches found
No related tags found
No related merge requests found
...@@ -24,10 +24,12 @@ export default function ConfigServer() { ...@@ -24,10 +24,12 @@ export default function ConfigServer() {
let [loading, setLoading] = useState(false); let [loading, setLoading] = useState(false);
let [error, setError] = useState(null); let [error, setError] = useState(null);
function getErrorMessage(error) { function getErrorMessage(error, url) {
switch (error) { switch (error) {
case 'network-failure': case 'network-failure':
return 'Server is not running at this URL'; return 'Server is not running at this URL';
case 'add-http':
return 'Server is not running at this URL. Did you mean to add "http://"?';
default: default:
return 'Server does not look like an Actual server. Is it set up correctly?'; return 'Server does not look like an Actual server. Is it set up correctly?';
} }
...@@ -41,11 +43,30 @@ export default function ConfigServer() { ...@@ -41,11 +43,30 @@ export default function ConfigServer() {
setError(null); setError(null);
setLoading(true); setLoading(true);
let { error } = await send('set-server-url', { url }); let { error } = await send('set-server-url', { url });
setLoading(false);
if (error) { if (
error === 'network-failure' &&
!url.startsWith('http://') &&
!url.startsWith('https://')
) {
let { error } = await send('set-server-url', { url: 'https://' + url });
if (error === 'network-failure') {
setError('add-http');
if (!url.startsWith('http://')) {
setUrl('http://' + url);
}
} else if (error) {
setError(error);
} else {
await dispatch(signOut());
history.push('/');
}
setLoading(false);
} else if (error) {
setLoading(false);
setError(error); setError(error);
} else { } else {
setLoading(false);
await dispatch(signOut()); await dispatch(signOut());
history.push('/'); history.push('/');
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment