Skip to content

Commit 22cc33e

Browse files
committed
Do a simple .well-known lookup for default_server_name for mobile guide
1 parent 559416d commit 22cc33e

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

‎src/vector/mobile_guide/index.js‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,36 @@ async function initPage() {
6262
}
6363

6464
if (serverName) {
65-
// TODO: TravisR .well-known lookup
65+
// We also do our own minimal .well-known validation to avoid pulling in the js-sdk
66+
try {
67+
const result = await fetch(`https://${serverName}/.well-known/matrix/client`);
68+
const wkConfig = await result.json();
69+
if (wkConfig && wkConfig['m.homeserver']) {
70+
hsUrl = wkConfig['m.homeserver']['base_url'];
71+
72+
if (wkConfig['m.identity_server']) {
73+
isUrl = wkConfig['m.identity_server']['base_url'];
74+
}
75+
}
76+
} catch (e) {
77+
console.error(e);
78+
return renderConfigError("Unable to fetch homeserver configuration");
79+
}
6680
}
6781

6882
if (defaultHsUrl) {
6983
hsUrl = defaultHsUrl;
7084
isUrl = defaultIsUrl;
7185
}
7286

87+
if (!hsUrl) {
88+
return renderConfigError("Unable to locate homeserver");
89+
}
90+
7391
if (hsUrl && !hsUrl.endsWith('/')) hsUrl += '/';
7492
if (isUrl && !isUrl.endsWith('/')) isUrl += '/';
7593

76-
if (hsUrl && hsUrl !== 'https://matrix.org/') {
94+
if (hsUrl !== 'https://matrix.org/') {
7795
document.getElementById('step2_container').style.display = 'block';
7896
document.getElementById('hs_url').innerText = hsUrl;
7997
document.getElementById('step_login_header').innerHTML= 'Step 3: Register or Log in';

0 commit comments

Comments
 (0)