Skip to content

Commit

Permalink
resolve conflict after merging wip/import-boot-config
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Nov 4, 2016
2 parents fd55fe1 + dd2d0ae commit bedb76a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function config ( ) {
env.DISPLAY_UNITS = readENV('DISPLAY_UNITS', 'mg/dl');
env.PORT = readENV('PORT', 1337);
env.HOSTNAME = readENV('HOSTNAME', null);
env.IMPORT_CONFIG = readENV('IMPORT_CONFIG', null);
env.static_files = readENV('NIGHTSCOUT_STATIC_FILES', __dirname + '/static/');

if (env.err) {
Expand Down
29 changes: 29 additions & 0 deletions lib/bootevent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,34 @@ function boot (env, language) {
return ctx.bootErrors && ctx.bootErrors.length > 0;
}

function augmentSettings (ctx, next) {
var configURL = env.IMPORT_CONFIG || null;
var url = require('url');
var href = null;
try {
href = url.parse(configURL).href;
} catch (e) {
}
if(configURL && href) {
var request = require('request');
console.log('Getting', href);
request.get({url: href, json: true}, function (err, resp, body) {
console.log("GOT", body);
if (err) {
console.log('Attempt to fetch config', href, 'failed.');
console.error(err);
throw err;
} else {
console.log('extending');
_.merge(env.settings, body);
}
next( );
});
} else {
next( );
}
}

function setupStorage (ctx, next) {

if (hasBootErrors(ctx)) {
Expand Down Expand Up @@ -187,6 +215,7 @@ function boot (env, language) {

return require('bootevent')( )
.acquire(checkEnv)
.acquire(augmentSettings)
.acquire(setupStorage)
.acquire(setupAuthorization)
.acquire(setupInternals)
Expand Down

0 comments on commit bedb76a

Please sign in to comment.