Skip to content

Commit

Permalink
fix: ensure app is initialized even when config fails to load
Browse files Browse the repository at this point in the history
This makes sure that the notification popups are working and can
inform the user about the potential syntax error in the config file.
  • Loading branch information
rchl committed Nov 30, 2020
1 parent 637e37f commit 4d3ec12
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ If you are running TileBoard for the first time, please rename "config.example.j
if (!window.CONFIG) {
alert(`The "${configName}.js" configuration file has loaded but window.CONFIG is not defined!
Please make sure that it defines a CONFIG variable with proper configuration.`);
return;
}
// Initialize the app even though we have no valid configuration so that notifications are working.
// @ts-ignore
window.window.initApp();
}
Expand Down
4 changes: 4 additions & 0 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ window.initApp = function () {
requireBase: false,
});

if (!window.CONFIG) {
return;
}

ApiProvider.setInitOptions({
wsUrl: window.CONFIG.wsUrl,
authToken: window.CONFIG.authToken,
Expand Down
5 changes: 5 additions & 0 deletions scripts/models/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ App.provider('Api', function () {
$Api.prototype._init = function () {
const self = this;

if (!self._url) {
console.info('Skipping API service initialization since no API URL was provided.');
return;
}

this._getToken().then(function (token) {
if (token) {
self._token = token.access_token;
Expand Down

0 comments on commit 4d3ec12

Please sign in to comment.