/*
** beelancer-api
** author: gordon hall
**
** load configuration
*/

var fs = require('fs')

if (!fs.existsSync(__dirname + '/config/settings.json')) {
  console.error('Config file [config/settings.json] missing!');
  console.error('Did you forget to run `make decrypt_config`?');
  process.exit(1);
}
 
var conf_time  = fs.statSync(__dirname + '/config/settings.json').mtime.getTime();
var cast5_time = fs.statSync(__dirname + '/config/settings.json.cast5').mtime.getTime();

if (conf_time < cast5_time) {
  console.error('Your config file is out of date!');
  console.error('You need to run `make decrypt_config` to update it.');
  process.exit(1);
}

var config = fs.readFileSync(__dirname + '/config/settings.json', 'utf8');

module.exports = JSON.parse(config)[process.env.NODE_ENV || 'local'];
