From 32eb96467fd6b1bbe0ca52f27be743d82bb7c91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Sun, 22 Nov 2020 15:07:12 +0100 Subject: [PATCH 1/4] Take baseurl into account, use original url, not LocalAddress --- src/scripts/clientUtils.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index b931fc64ac..f94045d5d2 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -29,23 +29,47 @@ export async function serverAddress() { // if (current) return Promise.resolve(current); const urls = []; + if (window.location.href.indexOf('/web/') !== -1) { // Do we polyfill String.prototype.includes? + const split = window.location.href.split('/web/'); + + for (let i=split.length - 1; i ; i--) { + urls.push(split.slice(0, i).join('/web/')); + } + } urls.push(window.location.origin); urls.push(`https://${window.location.hostname}:8920`); - urls.push(...await webSettings.getServers()); if (window.location.protocol === 'http') { urls.push(`http://${window.location.hostname}:8096`); } + urls.push(...await webSettings.getServers()); + + console.log("URL candidates:", urls); + const promises = urls.map(url => { - return fetch(`${url}/System/Info/Public`).then(resp => url).catch(error => { + return fetch(`${url}/System/Info/Public`).then(resp => { + return { + url: url, + response: resp, + }; + }).catch(error => { return Promise.resolve(); }); }); return Promise.all(promises).then(responses => { - responses = responses.filter(response => response); - return responses[0]; + responses = responses.filter(obj => obj && obj.response.ok); + return Promise.all(responses.map(obj => { + return { + url: obj.url, + config: obj.response.json(), + } + })); + }).then(configs => { + let selection = configs.find(obj => !obj.config.StartupWizardCompleted); + if (!selection) selection = configs[0]; + return Promise.resolve(selection.url); }).catch(error => { console.log(error); return Promise.resolve(); From 27b113efba642de8f071868df3c743a9904a26b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Sun, 22 Nov 2020 16:54:24 +0100 Subject: [PATCH 2/4] Fix lints --- src/scripts/clientUtils.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index f94045d5d2..5ac27a68d6 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -32,7 +32,7 @@ export async function serverAddress() { if (window.location.href.indexOf('/web/') !== -1) { // Do we polyfill String.prototype.includes? const split = window.location.href.split('/web/'); - for (let i=split.length - 1; i ; i--) { + for (let i = split.length - 1; i ; i--) { urls.push(split.slice(0, i).join('/web/')); } } @@ -45,13 +45,13 @@ export async function serverAddress() { urls.push(...await webSettings.getServers()); - console.log("URL candidates:", urls); + console.log('URL candidates:', urls); const promises = urls.map(url => { return fetch(`${url}/System/Info/Public`).then(resp => { return { url: url, - response: resp, + response: resp }; }).catch(error => { return Promise.resolve(); @@ -63,8 +63,8 @@ export async function serverAddress() { return Promise.all(responses.map(obj => { return { url: obj.url, - config: obj.response.json(), - } + config: obj.response.json() + }; })); }).then(configs => { let selection = configs.find(obj => !obj.config.StartupWizardCompleted); From 1d51b94d41bef0186575c98fbd1489e8247f808a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Tue, 24 Nov 2020 20:44:14 +0100 Subject: [PATCH 3/4] Address review --- src/scripts/clientUtils.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index 5ac27a68d6..69d64c671e 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -29,10 +29,10 @@ export async function serverAddress() { // if (current) return Promise.resolve(current); const urls = []; - if (window.location.href.indexOf('/web/') !== -1) { // Do we polyfill String.prototype.includes? + if (window.location.href.indexOf('/web/') !== -1) { const split = window.location.href.split('/web/'); - for (let i = split.length - 1; i ; i--) { + for (let i = split.length - 1; i > 0; i--) { urls.push(split.slice(0, i).join('/web/')); } } @@ -45,7 +45,7 @@ export async function serverAddress() { urls.push(...await webSettings.getServers()); - console.log('URL candidates:', urls); + console.debug('URL candidates:', urls); const promises = urls.map(url => { return fetch(`${url}/System/Info/Public`).then(resp => { @@ -67,8 +67,7 @@ export async function serverAddress() { }; })); }).then(configs => { - let selection = configs.find(obj => !obj.config.StartupWizardCompleted); - if (!selection) selection = configs[0]; + let selection = configs.find(obj => !obj.config.StartupWizardCompleted) || configs[0]; return Promise.resolve(selection.url); }).catch(error => { console.log(error); From ef3f6cb9508661d0b5c33758b5c87a5049b31e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Tue, 24 Nov 2020 21:20:05 +0100 Subject: [PATCH 4/4] JavaScript is a constant pain. --- src/scripts/clientUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index 69d64c671e..84e029f827 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -67,7 +67,7 @@ export async function serverAddress() { }; })); }).then(configs => { - let selection = configs.find(obj => !obj.config.StartupWizardCompleted) || configs[0]; + const selection = configs.find(obj => !obj.config.StartupWizardCompleted) || configs[0]; return Promise.resolve(selection.url); }).catch(error => { console.log(error);