Skip to content

Commit

Permalink
use the same protocol for .well-known lookup as in homeserver url fro…
Browse files Browse the repository at this point in the history
…m the login form, fixes #238
  • Loading branch information
aine-etke committed Dec 16, 2024
1 parent 71e90c1 commit 630286a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,26 @@ export const FetchConfig = async () => {
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
const homeserver = localStorage.getItem("home_server");
if (homeserver) {
try {
const resp = await fetch(`https://${homeserver}/.well-known/matrix/client`);
const configWK = await resp.json();
const resp = await fetch(`${protocol}://${homeserver}/.well-known/matrix/client`);
const configWK = await resp.json();
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 {
console.log(`Loaded https://${homeserver}.well-known/matrix/client`, configWK);
console.log(`Loaded ${protocol}://${homeserver}.well-known/matrix/client`, configWK);
LoadConfig(configWK[WellKnownKey]);
}
} 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);
}
}

Expand Down

0 comments on commit 630286a

Please sign in to comment.