Set configuration file by enviroment variable:

Enable ability to set configuration file by the enviroment variable
called MM_CONFIG_FILE.
This commit is contained in:
Rodrigo Ramírez Norambuena 2017-01-24 02:59:20 -03:00
parent 5d63065057
commit 86e553e756
2 changed files with 15 additions and 1 deletions

View File

@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Option to use RegExp in Calendar's titleReplace. - Option to use RegExp in Calendar's titleReplace.
- Hungarian Translation. - Hungarian Translation.
- Icelandic Translation. - Icelandic Translation.
- Enable ability to set configuration file by the enviroment variable called MM_CONFIG_FILE.
### Fixed ### Fixed
- Update .gitignore to not ignore default modules folder. - Update .gitignore to not ignore default modules folder.

View File

@ -17,6 +17,10 @@ console.log("Starting MagicMirror: v" + global.version);
// global absolute root path // global absolute root path
global.root_path = path.resolve(__dirname + "/../"); global.root_path = path.resolve(__dirname + "/../");
if (process.env.MM_CONFIG_FILE) {
global.configuration_file = process.env.MM_CONFIG_FILE;
}
// The next part is here to prevent a major exception when there // The next part is here to prevent a major exception when there
// is no internet connection. This could probable be solved better. // is no internet connection. This could probable be solved better.
process.on("uncaughtException", function (err) { process.on("uncaughtException", function (err) {
@ -41,7 +45,16 @@ var App = function() {
var loadConfig = function(callback) { var loadConfig = function(callback) {
console.log("Loading config ..."); console.log("Loading config ...");
var defaults = require(__dirname + "/defaults.js"); var defaults = require(__dirname + "/defaults.js");
var configFilename = path.resolve(global.root_path + "/config/config.js");
// For this check proposed to TestSuite
// https://forum.magicmirror.builders/topic/1456/test-suite-for-magicmirror/8
console.log(global.configuration_file);
if (global.configuration_file === undefined ) {
var configFilename = path.resolve(global.root_path + "/config/config.js");
} else {
var configFilename = path.resolve(global.configuration_file);
}
try { try {
fs.accessSync(configFilename, fs.F_OK); fs.accessSync(configFilename, fs.F_OK);
var c = require(configFilename); var c = require(configFilename);