diff --git a/src/components/views/dialogs/ServerPickerDialog.tsx b/src/components/views/dialogs/ServerPickerDialog.tsx index 9eb819c98e..c96da1b28e 100644 --- a/src/components/views/dialogs/ServerPickerDialog.tsx +++ b/src/components/views/dialogs/ServerPickerDialog.tsx @@ -14,7 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React, {createRef} from 'react'; +import React, {createRef} from "react"; +import {AutoDiscovery} from "matrix-js-sdk/src/autodiscovery"; import AutoDiscoveryUtils, {ValidatedServerConfig} from "../../../utils/AutoDiscoveryUtils"; import BaseDialog from './BaseDialog'; @@ -47,9 +48,10 @@ export default class ServerPickerDialog extends React.PureComponent({ - deriveData: async ({ value: hsUrl }) => { - // Always try and use the defaults first - const defaultConfig: ValidatedServerConfig = SdkConfig.get()["validated_server_config"]; - if (defaultConfig.hsUrl === hsUrl) return {}; + deriveData: async ({ value }) => { + let hsUrl = value.trim(); // trim to account for random whitespace + + // if the URL has no protocol, try validate it as a serverName via well-known + if (!hsUrl.includes("://")) { + try { + const discoveryResult = await AutoDiscovery.findClientConfig(hsUrl); + this.validatedConf = AutoDiscoveryUtils.buildValidatedConfigFromDiscovery(hsUrl, discoveryResult); + return {}; // we have a validated config, we don't need to try the other paths + } catch (e) { + console.error(`Attempted ${hsUrl} as a server_name but it failed`, e); + } + } + + // if we got to this stage then either the well-known failed or the URL had a protocol specified, + // so validate statically only. If the URL has no protocol, default to https. + if (!hsUrl.includes("://")) { + hsUrl = "https://" + hsUrl; + } try { this.validatedConf = await AutoDiscoveryUtils.validateServerConfigWithStaticUrls(hsUrl); @@ -81,17 +98,22 @@ export default class ServerPickerDialog extends React.PureComponent