Skip to content

Commit 40a47f8

Browse files
authored
Allow Riot to load up different configs depending on the domain (element-hq#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`.
1 parent caa5751 commit 40a47f8

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎src/vector/index.js‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ var makeRegistrationUrl = function(params) {
187187

188188
window.addEventListener('hashchange', onHashChange);
189189

190-
function getConfig() {
190+
function getConfig(configJsonFilename) {
191191
let deferred = Promise.defer();
192192

193193
request(
194-
{ method: "GET", url: "config.json" },
194+
{ method: "GET", url: configJsonFilename },
195195
(err, response, body) => {
196196
if (err || response.status < 200 || response.status >= 300) {
197197
// Lack of a config isn't an error, we should
@@ -261,10 +261,20 @@ async function loadApp() {
261261
}
262262
}
263263

264+
// Load the config file. First try to load up a domain-specific config of the
265+
// form "config.$domain.json" and if that fails, fall back to config.json.
264266
let configJson;
265267
let configError;
266268
try {
267-
configJson = await getConfig();
269+
try {
270+
configJson = await getConfig(`config.${document.domain}.json`);
271+
// 404s succeed with an empty json config, so check that there are keys
272+
if (Object.keys(configJson).length === 0) {
273+
throw new Error(); // throw to enter the catch
274+
}
275+
} catch (e) {
276+
configJson = await getConfig("config.json");
277+
}
268278
} catch (e) {
269279
configError = e;
270280
}

0 commit comments

Comments
 (0)