diff --git a/config/autoconfig.js b/config/autoconfig.js deleted file mode 100644 index 7c7142d..0000000 --- a/config/autoconfig.js +++ /dev/null @@ -1,22 +0,0 @@ -var fs = require('fs'); -var crypto = require('crypto'); - -module.exports = function (expectedConfigFile) { - - if (! fs.existsSync(expectedConfigFile)) { - var buf = crypto.randomBytes(256); - var hash = crypto.createHash('sha1').update(buf).digest('hex'); - - // TODO: refactor - console.log('***** NOTICE ****** \n'); - console.log('You are missing "' + expectedConfigFile + '"'); - console.log('Creating a configuration automatically for you....'); - console.log('Your Freight Server password is: \n'); - console.log(hash); - console.log('\n Use the password above to generate bundles.'); - var devSampleFile = JSON.parse(fs.readFileSync(__dirname + '/dev.json-dist')); - devSampleFile.password = hash; - fs.writeFileSync(expectedConfigFile, JSON.stringify(devSampleFile), null, 4); - } - -}; diff --git a/config/config.js b/config/config.js index e2b6d77..35ddd3b 100644 --- a/config/config.js +++ b/config/config.js @@ -3,15 +3,13 @@ * See https://github.com/mozilla/node-convict/blob/master/README.md for details. */ var convict = require('convict'); +var fs = require('fs'); module.exports = function () { - // Check if we need to auto configure for a fast start. var env = process.env.NODE_ENV || 'dev'; var configFile = process.env.FREIGHT_CONFIG || __dirname + '/' + env + '.json'; - require('./autoconfig')(configFile); - var conf = convict({ env: { doc: 'The applicaton environment.', @@ -40,43 +38,51 @@ module.exports = function () { limit: { doc: 'The bundle transmission size limit, in kb.', format: 'nat', - default: 500 + default: 500, + env: 'LIMIT' }, password: { doc: 'The password that is used to create Freight bundles.', format: String, - default: '' + default: '', + env: 'FREIGHT_PASSWORD' }, storage: { // TODO: You need to create this directory if it does not exist. // This directory is also used as a static file directory for Freight bundles. doc: 'Default bundle storage directory. Make sure it is somewhere in the Freight Server directory.', format: String, - default: __dirname + '/../storage' + default: __dirname + '/../storage', + env: 'STORAGE_DIRECTORY' }, tempDir: { // TODO: You need to create this directory if it does not exist. doc: 'Default directory for temporary files.', format: String, - default: __dirname + '/../temp' + default: __dirname + '/../temp', + env: 'TEMP_DIRECTORY' }, // Redis config, see https://github.com/learnboost/kue#redis-connection-settings redis: { port: { doc: 'Redis Port', format: 'port', - default: 6379 + default: 6379, + env: 'REDIS_PORT' }, host: { doc: 'Redis IP address to bind.', - format: 'ipaddress', - default: '127.0.0.1' + format: String, + default: '127.0.0.1', + env: 'REDIS_HOST' }, auth: { doc: 'Redis Password.', format: String, - default: '' + default: '', + env: 'REDIS_PASSWORD' }, + // TODO : see how we can extract redis options from env variables options: { doc: 'Redis Options.', format: Object, @@ -87,14 +93,17 @@ module.exports = function () { delay: { doc: 'Repository update check delay in milliseconds', format: 'nat', - default: 60 * 60000 + default: 60 * 60000, + env: 'TRACK_DELAY' } } }); // load environment dependent configuration - // TODO: development only for now, change it later. - conf.loadFile(configFile); + if (fs.existsSync(configFile)) { + // TODO: development only for now, change it later. + conf.loadFile(configFile); + } // perform configuration validation conf.validate();