Skip to content

Commit

Permalink
Allow default_server_config as a fallback config
Browse files Browse the repository at this point in the history
The configuration provided with default_server_config can be used as a
suitable fallback in case the well-known discovery failed.

Using either of `default_server_config` or `default_server_name` is
still supported and works like before.

Signed-off-by: Yorusaka Miyabi <shadowrz@disroot.org>
  • Loading branch information
ShadowRZ committed Jun 29, 2023
1 parent 4f1ce3c commit f880422
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/vector/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@ async function verifyServerConfig(): Promise<IConfigOptions> {
const isUrl = config["default_is_url"];

const incompatibleOptions = [wkConfig, serverName, hsUrl].filter((i) => !!i);
if (incompatibleOptions.length > 1) {
// noinspection ExceptionCaughtLocallyJS
throw new UserFriendlyError(
"Invalid configuration: can only specify one of default_server_config, default_server_name, " +
"or default_hs_url.",
);
}
if (incompatibleOptions.length < 1) {
// noinspection ExceptionCaughtLocallyJS
throw new UserFriendlyError("Invalid configuration: no default server specified.");
Expand All @@ -201,7 +194,7 @@ async function verifyServerConfig(): Promise<IConfigOptions> {
}

let discoveryResult: ClientConfig | undefined;
if (wkConfig) {
if (!serverName && wkConfig) {
logger.log("Config uses a default_server_config - validating object");
discoveryResult = await AutoDiscovery.fromDiscoveryConfig(wkConfig);
}
Expand All @@ -213,6 +206,10 @@ async function verifyServerConfig(): Promise<IConfigOptions> {
"use default_server_config instead.",
);
discoveryResult = await AutoDiscovery.findClientConfig(serverName);
if (discoveryResult["m.homeserver"].base_url === null && wkConfig) {
logger.log("Finding base_url failed but a default_server_config was found - using it as a fallback");
discoveryResult = await AutoDiscovery.fromDiscoveryConfig(wkConfig);
}
}

validatedConfig = AutoDiscoveryUtils.buildValidatedConfigFromDiscovery(serverName, discoveryResult, true);
Expand Down

0 comments on commit f880422

Please sign in to comment.