'use strict';

/*
read config files from:
  * config_default.js (built-in)
  * /srv/itranswarp/conf/config_override.js (if file exist)

You should override some configurations in /srv/itranswarp/conf/config_override.js:

    // config_override.js:
    exports = module.exports = {
        "db": {
            "host": "192.168.0.101", // a specific IP of mysql server
            "port": 3307 // a specific port of mysql server
        }
    }
*/

const
    overrideConfigPath = '/srv/itranswarp/conf/config_override.js',
    _ = require('lodash'),
    fs = require('fs'),
    logger = require('./logger');

let cfg = require('./config_default');

if (fs.existsSync(overrideConfigPath)) {
    logger.info(`load ${overrideConfigPath}...`);
    let ovr = require(overrideConfigPath);
    cfg = _.merge(cfg, ovr);
}

cfg.version = '1.0';
// replace by deployment:
cfg.build = '$BUILD$';

logger.debug('configuration loaded: ' + JSON.stringify(cfg, null, '  '));

module.exports = cfg;

@@ -72,37 +72,16 @@
 in)%0A  * 
-/srv/itranswarp/conf/
 config_o
@@ -151,37 +151,16 @@
 ions in 
-/srv/itranswarp/conf/
 config_o
@@ -408,76 +408,8 @@
 nst%0A
-    overrideConfigPath = '/srv/itranswarp/conf/config_override.js',%0A
     
@@ -435,32 +435,8 @@
 '),%0A
-    fs = require('fs'),%0A
     
@@ -510,243 +510,195 @@
 );%0A%0A
-if (fs.existsSync(overrideConfigPath)) %7B%0A    logger.info(%60load $%7BoverrideConfigPath%7D...%60);%0A    let ovr = require(overrideConfigPath);%0A    cfg = _.merge(cfg, ovr);%0A%7D%0A%0Acfg.version = '1.0';%0A// replace by deployment:%0Acfg.build = '$BUILD$';
+try %7B%0A    let ovr = require('./config_override');%0A    cfg = _.merge(cfg, ovr);%0A    logger.warn('loaded config_override.');%0A%7D catch (e) %7B%0A    logger.warn('Cannot read config_override.');%0A%7D
 %0A%0Alo

load config_override.js in same dir