1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Take baseurl into account, use original url, not LocalAddress

This commit is contained in:
Odd Stråbø 2020-11-22 15:07:12 +01:00
parent 89666237cb
commit 32eb96467f

View file

@ -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();