From 40a47f8c7a842297da51abd37528d87ea108a744 Mon Sep 17 00:00:00 2001 From: Kegsay Date: Fri, 14 Jul 2017 15:05:07 +0100 Subject: [PATCH] Allow Riot to load up different configs depending on the domain (#4575) Initially try to load `config.$domain.json` and only if that fails, load `config.json`. Configs are not muxxed in any way, it either entirely uses the domain config, or entirely uses `config.json`. --- src/vector/index.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index 0cf8563f16..c0cb64102e 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -187,11 +187,11 @@ var makeRegistrationUrl = function(params) { window.addEventListener('hashchange', onHashChange); -function getConfig() { +function getConfig(configJsonFilename) { let deferred = Promise.defer(); request( - { method: "GET", url: "config.json" }, + { method: "GET", url: configJsonFilename }, (err, response, body) => { if (err || response.status < 200 || response.status >= 300) { // Lack of a config isn't an error, we should @@ -261,10 +261,20 @@ async function loadApp() { } } + // Load the config file. First try to load up a domain-specific config of the + // form "config.$domain.json" and if that fails, fall back to config.json. let configJson; let configError; try { - configJson = await getConfig(); + try { + configJson = await getConfig(`config.${document.domain}.json`); + // 404s succeed with an empty json config, so check that there are keys + if (Object.keys(configJson).length === 0) { + throw new Error(); // throw to enter the catch + } + } catch (e) { + configJson = await getConfig("config.json"); + } } catch (e) { configError = e; }