support defaults when new config files are not found, for backwards compatibility

This commit is contained in:
Iuri Matias 2017-03-05 21:27:33 -05:00
parent 007be84f23
commit 96d1361dd8
1 changed files with 39 additions and 7 deletions

View File

@ -95,7 +95,18 @@ Config.prototype.loadContractsConfigFile = function() {
Config.prototype.loadStorageConfigFile = function() {
var configObject = {};
var configObject = {
"default": {
"enabled": true,
"available_providers": ["ipfs"],
"ipfs_bin": "ipfs",
"provider": "ipfs",
"host": "localhost",
"port": 5001
},
"development": {
}
};
//var configPlugins = this.plugins.getPluginsFor('storageConfig');
//if (configPlugins.length > 0) {
@ -106,8 +117,12 @@ Config.prototype.loadStorageConfigFile = function() {
// });
//}
var storageConfig = fs.readJSONSync(this.configDir + "storage.json");
configObject = utils.recursiveMerge(configObject, storageConfig);
var storageConfig;
if (fs.existsSync(this.configDir + "storage.json")) {
storageConfig = fs.readJSONSync(this.configDir + "storage.json");
configObject = utils.recursiveMerge(configObject, storageConfig);
}
var defaultStorageConfig = configObject['default'];
var envStorageConfig = configObject[this.env];
@ -123,7 +138,13 @@ Config.prototype.loadStorageConfigFile = function() {
};
Config.prototype.loadCommunicationConfigFile = function() {
var configObject = {};
var configObject = {
"default": {
"enabled": true,
"provider": "whisper",
"available_providers": ["whisper", "orbit"]
}
};
//var configPlugins = this.plugins.getPluginsFor('communicationConfig');
//if (configPlugins.length > 0) {
@ -134,14 +155,20 @@ Config.prototype.loadCommunicationConfigFile = function() {
// });
//}
var communicationConfig = fs.readJSONSync(this.configDir + "communication.json");
configObject = utils.recursiveMerge(configObject, communicationConfig);
var communicationConfig;
if (fs.existsSync(this.configDir + "communication.json")) {
communicationConfig = fs.readJSONSync(this.configDir + "communication.json");
configObject = utils.recursiveMerge(configObject, communicationConfig);
}
var defaultCommunicationConfig = configObject['default'];
var envCommunicationConfig = configObject[this.env];
var mergedConfig = utils.recursiveMerge(defaultCommunicationConfig, envCommunicationConfig);
this.communicationConfig = mergedConfig || {};
// TODO: probably not necessary if the default object is done right
if (this.communicationConfig.enabled === undefined) {
this.communicationConfig.enabled = true;
}
@ -151,7 +178,12 @@ Config.prototype.loadCommunicationConfigFile = function() {
};
Config.prototype.loadWebServerConfigFile = function() {
var webServerConfigJSON = fs.readJSONSync(this.configDir + "webserver.json");
var webServerConfigJSON;
if (fs.existsSync(this.configDir + "webserver.json")) {
webServerConfigJSON = fs.readJSONSync(this.configDir + "webserver.json");
} else {
webServerConfigJSON = {};
}
var defaultWebConfig = {
"enabled": true,
"host": "localhost",