mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 18:25:49 +03:00
Merge pull request #2534 from vector-im/dbkr/config_accept_blank
Use the defaults if given a blank config file
This commit is contained in:
commit
67dbd9fba9
1 changed files with 16 additions and 9 deletions
|
@ -179,14 +179,27 @@ function getConfig() {
|
||||||
let deferred = q.defer();
|
let deferred = q.defer();
|
||||||
|
|
||||||
request(
|
request(
|
||||||
{ method: "GET", url: "config.json", json: true },
|
{ method: "GET", url: "config.json" },
|
||||||
(err, response, body) => {
|
(err, response, body) => {
|
||||||
if (err || response.status < 200 || response.status >= 300) {
|
if (err || response.status < 200 || response.status >= 300) {
|
||||||
|
// Lack of a config isn't an error, we should
|
||||||
|
// just use the defaults.
|
||||||
|
// Also treat a blank config as no config because
|
||||||
|
// we don't get 404s from file: URIs so this is the
|
||||||
|
// only way we can not fail if the file doesn't exist
|
||||||
|
// when loading from a file:// URI.
|
||||||
|
if (( err && err.response.status == 404) || body == '') {
|
||||||
|
deferred.resolve({});
|
||||||
|
}
|
||||||
deferred.reject({err: err, response: response});
|
deferred.reject({err: err, response: response});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
deferred.resolve(body);
|
// We parse the JSON ourselves rather than use the JSON
|
||||||
|
// parameter, since this throws a parse error on empty
|
||||||
|
// which breaks if there's no config.json and we're
|
||||||
|
// loading from the filesystem (see above).
|
||||||
|
deferred.resolve(JSON.parse(body));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -239,13 +252,7 @@ async function loadApp() {
|
||||||
try {
|
try {
|
||||||
configJson = await getConfig();
|
configJson = await getConfig();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// On 404 errors, carry on without a config,
|
configError = e;
|
||||||
// but on other errors, fail, otherwise it will
|
|
||||||
// lead to subtle errors where the app runs with
|
|
||||||
// the default config if it fails to fetch config.json.
|
|
||||||
if (e.response.status != 404) {
|
|
||||||
configError = e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Vector starting at "+window.location);
|
console.log("Vector starting at "+window.location);
|
||||||
|
|
Loading…
Reference in a new issue