Remove extraneous nconf setup.

This commit is contained in:
Blade Barringer
2015-11-08 08:56:27 -06:00
parent 1ef6839eea
commit 447d4c332d
2 changed files with 15 additions and 22 deletions
+7 -15
View File
@@ -4,8 +4,8 @@ var crypto = require('crypto');
var path = require("path");
var request = require('request');
// Set when utils.setupConfig is run
var isProd, baseUrl;
const IS_PROD = nconf.get('IS_PROD');
const BASE_URL = nconf.get('BASE_URL');
module.exports.sendEmail = function(mailData) {
var smtpTransport = nodemailer.createTransport("SMTP",{
@@ -59,7 +59,7 @@ module.exports.txnEmail = function(mailingInfoArray, emailType, variables, perso
var mailingInfoArray = Array.isArray(mailingInfoArray) ? mailingInfoArray : [mailingInfoArray];
var variables = [
{name: 'BASE_URL', content: baseUrl}
{name: 'BASE_URL', content: BASE_URL}
].concat(variables || []);
// It's important to pass at least a user with its `preferences` as we need to check if he unsubscribed
@@ -120,7 +120,7 @@ module.exports.txnEmail = function(mailingInfoArray, emailType, variables, perso
});
}
if(isProd && mailingInfoArray.length > 0){
if(IS_PROD && mailingInfoArray.length > 0){
request({
url: nconf.get('EMAIL_SERVER:url') + '/job',
method: 'POST',
@@ -167,20 +167,12 @@ module.exports.analytics = { track: function() { }, trackPurchase: function() {
* Load nconf and define default configuration values if config.json or ENV vars are not found
*/
module.exports.setupConfig = function(){
nconf.argv()
.env()
//.file('defaults', path.join(path.resolve(__dirname, '../config.json.example')))
.file('user', path.join(path.resolve(__dirname, './../../../config.json')));
if (nconf.get('NODE_ENV') === "development")
if (nconf.get('IS_DEV'))
Error.stackTraceLimit = Infinity;
//if (nconf.get('NODE_ENV') === 'production')
//if (nconf.get('IS_PROD'))
//require('newrelic');
isProd = nconf.get('NODE_ENV') === 'production';
baseUrl = nconf.get('BASE_URL');
var analytics = isProd && require('./analytics');
var analytics = IS_PROD && require('./analytics');
var analyticsTokens = {
amplitudeToken: nconf.get('AMPLITUDE_KEY'),
googleAnalytics: nconf.get('GA_ID')
+8 -7
View File
@@ -1,4 +1,5 @@
require('babel/register');
require('./libs/api-v3/setupNconf')();
// Only do the minimal amount of work before forking just in case of a dyno restart
var cluster = require("cluster");
var _ = require('lodash');
@@ -6,12 +7,12 @@ var nconf = require('nconf');
var utils = require('./libs/utils');
utils.setupConfig();
var logging = require('./libs/logging');
var isProd = nconf.get('NODE_ENV') === 'production';
var isDev = nconf.get('NODE_ENV') === 'development';
var IS_PROD = nconf.get('IS_PROD');
var IS_DEV = nconf.get('IS_DEV');
var DISABLE_LOGGING = nconf.get('DISABLE_REQUEST_LOGGING');
var cores = +nconf.get("WEB_CONCURRENCY") || 0;
if (cores!==0 && cluster.isMaster && (isDev || isProd)) {
if (cores!==0 && cluster.isMaster && (IS_DEV || IS_PROD)) {
// Fork workers. If config.json has CORES=x, use that - otherwise, use all cpus-1 (production)
for (var i = 0; i < cores; i += 1) {
cluster.fork();
@@ -41,7 +42,7 @@ if (cores!==0 && cluster.isMaster && (isDev || isProd)) {
var mongoose = require('mongoose');
// Use Q promises instead of mpromise in mongoose
mongoose.Promise = require('q');
var mongooseOptions = !isProd ? {} : {
var mongooseOptions = !IS_PROD ? {} : {
replset: { socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 } },
server: { socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 } }
};
@@ -113,7 +114,7 @@ if (cores!==0 && cluster.isMaster && (isDev || isProd)) {
/* OLD APP IS DISABLED UNTIL COMPATIBLE WITH NEW MODELS
//require('./middlewares/apiThrottle')(oldApp);
oldApp.use(require('./middlewares/domain')(server,mongoose));
if (!isProd && !DISABLE_LOGGING) oldApp.use(require('morgan')("dev"));
if (!IS_PROD && !DISABLE_LOGGING) oldApp.use(require('morgan')("dev"));
oldApp.use(require('compression')());
oldApp.set("views", __dirname + "/../views");
oldApp.set("view engine", "jade");
@@ -161,7 +162,7 @@ if (cores!==0 && cluster.isMaster && (isDev || isProd)) {
oldApp.use('/export', require('./routes/dataexport'));
require('./routes/api-v2/swagger')(swagger, v2);
var maxAge = isProd ? 31536000000 : 0;
var maxAge = IS_PROD ? 31536000000 : 0;
// Cache emojis without copying them to build, they are too many
oldApp.use(express['static'](path.join(__dirname, "/../build"), { maxAge: maxAge }));
oldApp.use('/common/dist', express['static'](publicDir + "/../../common/dist", { maxAge: maxAge }));
@@ -172,7 +173,7 @@ if (cores!==0 && cluster.isMaster && (isDev || isProd)) {
oldApp.use(require('./middlewares/errorHandler'));
*/
server.on('request', app);
server.listen(app.get("port"), function() {
return logging.info("Express server listening on port " + app.get("port"));