Skip to content

Commit c2b487c

Browse files
committed
Support no config file when loading from files
file: URIs don't produce 404s.
1 parent 8edefe9 commit c2b487c

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/vector/index.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,27 @@ function getConfig() {
173173
let deferred = q.defer();
174174

175175
request(
176-
{ method: "GET", url: "config.json", json: true },
176+
{ method: "GET", url: "config.json" },
177177
(err, response, body) => {
178178
if (err || response.status < 200 || response.status >= 300) {
179+
// Lack of a config isn't an error, we should
180+
// just use the defaults.
181+
// Also treat a blank config as no config because
182+
// we don't get 404s from file: URIs so this is the
183+
// only way we can not fail if the file doesn't exist
184+
// when loading from a file:// URI.
185+
if (( err && err.response.status == 404) || body == '') {
186+
deferred.resolve({});
187+
}
179188
deferred.reject({err: err, response: response});
180189
return;
181190
}
182191

183-
deferred.resolve(body);
192+
// We parse the JSON ourselves rather than use the JSON
193+
// parameter, since this throws a parse error on empty
194+
// which breaks if there's no config.json and we're
195+
// loading from the filesystem (see above).
196+
deferred.resolve(iJSON.parse(body));
184197
}
185198
);
186199

@@ -233,13 +246,7 @@ async function loadApp() {
233246
try {
234247
configJson = await getConfig();
235248
} catch (e) {
236-
// On 404 errors, carry on without a config,
237-
// but on other errors, fail, otherwise it will
238-
// lead to subtle errors where the app runs with
239-
// the default config if it fails to fetch config.json.
240-
if (e.response.status != 404) {
241-
configError = e;
242-
}
249+
configError = e;
243250
}
244251

245252
console.log("Vector starting at "+window.location);

0 commit comments

Comments
 (0)