Autoconfiguration before bootstrap.
This patch delays the application bootstrap until we've tried to load and inject parameters saved in an external configuration file. If that file isn't there, the application will fall back to its own sane defaults, however this will give us an opportunity to more gracefully configure the webclient for each install. Example: Client and API are not on the same host. Change-Id: I1d0ce573dd05faa1efb325871ad5c30f08529205
This commit is contained in:
parent
73fc59f8f0
commit
941b12aec2
50
src/app/storyboard/auto_configuration.js
Normal file
50
src/app/storyboard/auto_configuration.js
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Automatic configuration loader. Checks the /config endpoint, and if
|
||||
* it receives a JSON hash will load all the found values into the application
|
||||
* module.
|
||||
*/
|
||||
angular.element(document)
|
||||
.ready(function () {
|
||||
'use strict';
|
||||
|
||||
var initInjector = angular.injector(['ng']);
|
||||
var $http = initInjector.get('$http');
|
||||
var $log = initInjector.get('$log');
|
||||
|
||||
function initializeApplication(config) {
|
||||
// Load everything we got into our module.
|
||||
for (var key in config) {
|
||||
$log.debug('Configuration: ' + key + ' -> ' + config[key]);
|
||||
angular.module('storyboard').constant(key, config[key]);
|
||||
}
|
||||
angular.bootstrap(document, ['storyboard']);
|
||||
}
|
||||
|
||||
$log.info('Attempting to load parameters from ./config.json');
|
||||
$http.get('./config.json').then(
|
||||
function (response) {
|
||||
initializeApplication(response.data);
|
||||
},
|
||||
function () {
|
||||
$log.warn('Cannot load ./config.json, using defaults.');
|
||||
initializeApplication({});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
@ -14,7 +14,7 @@
|
||||
License for the specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<html id="ng-app" ng-app="storyboard">
|
||||
<html id="ng-app">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="description" content="">
|
||||
|
Loading…
x
Reference in New Issue
Block a user