Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow default_server_config as a fallback config #25682

Merged
merged 7 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ One of the following options **must** be supplied:
being optional.

If a combination of these three methods is used then Element will fail to load. This is because it is unclear which
ShadowRZ marked this conversation as resolved.
Show resolved Hide resolved
should be considered "first".
should be considered "first". However, if both `default_server_config` and `default_server_name` are used, Element will
try to look up the connection infomation using `.well-known`, and if that fails, take `default_server_config` as the
homeserver connection infomation.

## Labs flags

Expand Down
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.",
);
}
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
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