use the same protocol for .well-known lookup as in homeserver url from the login form, fixes #238

This commit is contained in:
Aine
2024-12-16 12:44:00 +02:00
parent 71e90c12a7
commit 630286a781

View File

@@ -31,20 +31,26 @@ export const FetchConfig = async () => {
console.error(e); console.error(e);
} }
let protocol = "https";
const baseURL = localStorage.getItem("base_url");
if (baseURL && baseURL.startsWith("http://")) {
protocol = "http";
}
// if home_server is set, try to load https://home_server/.well-known/matrix/client // if home_server is set, try to load https://home_server/.well-known/matrix/client
const homeserver = localStorage.getItem("home_server"); const homeserver = localStorage.getItem("home_server");
if (homeserver) { if (homeserver) {
try { try {
const resp = await fetch(`https://${homeserver}/.well-known/matrix/client`); const resp = await fetch(`${protocol}://${homeserver}/.well-known/matrix/client`);
const configWK = await resp.json(); const configWK = await resp.json();
if (!configWK[WellKnownKey]) { if (!configWK[WellKnownKey]) {
console.log(`Loaded https://${homeserver}.well-known/matrix/client, but it doesn't contain ${WellKnownKey} key, skipping`, configWK); console.log(`Loaded ${protocol}://${homeserver}.well-known/matrix/client, but it doesn't contain ${WellKnownKey} key, skipping`, configWK);
} else { } else {
console.log(`Loaded https://${homeserver}.well-known/matrix/client`, configWK); console.log(`Loaded ${protocol}://${homeserver}.well-known/matrix/client`, configWK);
LoadConfig(configWK[WellKnownKey]); LoadConfig(configWK[WellKnownKey]);
} }
} catch (e) { } catch (e) {
console.log(`https://${homeserver}/.well-known/matrix/client not found, skipping`, e); console.log(`${protocol}://${homeserver}/.well-known/matrix/client not found, skipping`, e);
} }
} }