mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
don't fail login on missing cors on well-known
This commit is contained in:
parent
c0d3c950b0
commit
59605a2a57
@ -32,28 +32,35 @@ function getRetryHomeserver(homeserver) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function lookupHomeserver(homeserver, request) {
|
async function getWellKnownResponse(homeserver, request) {
|
||||||
homeserver = normalizeHomeserver(homeserver);
|
|
||||||
const requestOptions = {format: "json", timeout: 30000, method: "GET"};
|
const requestOptions = {format: "json", timeout: 30000, method: "GET"};
|
||||||
let wellKnownResponse = null;
|
let wellKnownResponse = null;
|
||||||
while (!wellKnownResponse) {
|
while (!wellKnownResponse) {
|
||||||
try {
|
try {
|
||||||
const wellKnownUrl = `${homeserver}/.well-known/matrix/client`;
|
const wellKnownUrl = `${homeserver}/.well-known/matrix/client`;
|
||||||
wellKnownResponse = await request(wellKnownUrl, requestOptions).response();
|
return await request(wellKnownUrl, requestOptions).response();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.name === "ConnectionError") {
|
if (err.name === "ConnectionError") {
|
||||||
const retryHS = getRetryHomeserver(homeserver);
|
const retryHS = getRetryHomeserver(homeserver);
|
||||||
if (retryHS) {
|
if (retryHS) {
|
||||||
homeserver = retryHS;
|
homeserver = retryHS;
|
||||||
} else {
|
} else {
|
||||||
throw err;
|
// don't fail lookup on a ConnectionError,
|
||||||
|
// there might be a missing CORS header on a 404 response or something,
|
||||||
|
// which won't be a problem necessarily with homeserver requests later on ...
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (wellKnownResponse.status === 200) {
|
}
|
||||||
|
|
||||||
|
export async function lookupHomeserver(homeserver, request) {
|
||||||
|
homeserver = normalizeHomeserver(homeserver);
|
||||||
|
const wellKnownResponse = await getWellKnownResponse(homeserver, request);
|
||||||
|
if (wellKnownResponse && wellKnownResponse.status === 200) {
|
||||||
const {body} = wellKnownResponse;
|
const {body} = wellKnownResponse;
|
||||||
const wellKnownHomeserver = body["m.homeserver"]?.["base_url"];
|
const wellKnownHomeserver = body["m.homeserver"]?.["base_url"];
|
||||||
if (typeof wellKnownHomeserver === "string") {
|
if (typeof wellKnownHomeserver === "string") {
|
||||||
|
Loading…
Reference in New Issue
Block a user