0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

🎨 replace process.env.NODE_ENV usages by config.get('env') (#7544)

closes #6629

- i had the case that in gravatar process.env.NODE_ENV was undefined and indexOf of undefined crashe my application
- so always use config to read current env
This commit is contained in:
Katharina Irrgang 2016-10-11 14:53:52 +02:00 committed by Hannah Wolfe
parent 9fad7f1d69
commit 677502813e
11 changed files with 27 additions and 33 deletions

View file

@ -22,7 +22,7 @@ function fetchAvailableTimezones() {
function getAboutConfig() {
return {
version: ghostVersion.full,
environment: process.env.NODE_ENV,
environment: config.get('env'),
database: config.get('database').client,
mail: _.isObject(config.get('mail')) ? config.get('mail').transport : ''
};

View file

@ -2,15 +2,16 @@
// API for sending Mail
var Promise = require('bluebird'),
config = require('../config'),
pipeline = require('../utils/pipeline'),
errors = require('../errors'),
mail = require('../mail'),
Models = require('../models'),
utils = require('./utils'),
notifications = require('./notifications'),
docName = 'mail',
i18n = require('../i18n'),
mode = process.env.NODE_ENV,
docName = 'mail',
mode = config.get('env'),
testing = mode !== 'production' && mode !== 'development',
mailer,
apiMail;

View file

@ -24,7 +24,7 @@ function ping(post) {
url = utils.url.urlFor('post', {post: post}, true);
// Only ping when in production and not a page
if (process.env.NODE_ENV !== 'production' || post.page || config.isPrivacyDisabled('useRpcPing')) {
if (config.get('env') !== 'production' || post.page || config.isPrivacyDisabled('useRpcPing')) {
return;
}

View file

@ -3,7 +3,8 @@
//
// Returns the path to the specified asset. The ghost flag outputs the asset path for the Ghost admin
var getAssetUrl = require('../data/meta/asset_url'),
var config = require('../config'),
getAssetUrl = require('../data/meta/asset_url'),
hbs = require('express-hbs');
function asset(path, options) {
@ -14,7 +15,7 @@ function asset(path, options) {
isAdmin = options.hash.ghost;
minify = options.hash.minifyInProduction;
}
if (process.env.NODE_ENV !== 'production') {
if (config.get('env') !== 'production') {
minify = false;
}
return new hbs.handlebars.SafeString(

View file

@ -1,4 +1,5 @@
var _ = require('lodash'),
config = require('../config'),
utils;
utils = {
@ -6,7 +7,7 @@ utils = {
linkTemplate: _.template('<a href="<%= url %>"><%= text %></a>'),
scriptTemplate: _.template('<script src="<%= source %>?v=<%= version %>"></script>'),
inputTemplate: _.template('<input class="<%= className %>" type="<%= type %>" name="<%= name %>" <%= extras %> />'),
isProduction: process.env.NODE_ENV === 'production',
isProduction: config.get('env') === 'production',
// @TODO this can probably be made more generic and used in more places
findKey: function findKey(key, object, data) {
if (object && _.has(object, key) && !_.isEmpty(object[key])) {

View file

@ -331,7 +331,7 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
requestedColumns = options.columns;
// Set this to true or pass ?debug=true as an API option to get output
itemCollection.debug = options.debug && process.env.NODE_ENV !== 'production';
itemCollection.debug = options.debug && config.get('env') !== 'production';
// Filter options so that only permitted ones remain
options = this.filterOptions(options, 'findPage');

View file

@ -1,7 +1,7 @@
var ghostBookshelf = require('./base'),
crypto = require('crypto'),
var crypto = require('crypto'),
uuid = require('node-uuid'),
ghostBookshelf = require('./base'),
config = require('../config'),
Client,
Clients;
@ -10,7 +10,7 @@ Client = ghostBookshelf.Model.extend({
tableName: 'clients',
defaults: function defaults() {
var env = process.env.NODE_ENV,
var env = config.get('env'),
secret = env.indexOf('testing') !== 0 ? crypto.randomBytes(6).toString('hex') : 'not_available';
return {

View file

@ -9,7 +9,7 @@ module.exports.lookup = function lookup(userData, timeout) {
'?s=250';
return new Promise(function gravatarRequest(resolve) {
if (config.isPrivacyDisabled('useGravatar') || process.env.NODE_ENV.indexOf('testing') > -1) {
if (config.isPrivacyDisabled('useGravatar') || config.get('env').indexOf('testing') > -1) {
return resolve(userData);
}

View file

@ -14,9 +14,7 @@ var should = require('should'),
// Thing we are testing
configUtils = require('../utils/configUtils'),
config = configUtils.config,
// storing current environment
currentEnv = process.env.NODE_ENV;
config = configUtils.config;
i18n.init();

View file

@ -1,14 +1,15 @@
var should = require('should'),
sinon = require('sinon'),
nock = require('nock'),
tmp = require('tmp'),
join = require('path').join,
fs = require('fs'),
configUtils = require('../utils/configUtils'),
parsePackageJson = require('../../server/utils/parse-package-json'),
readDirectory = require('../../server/utils/read-directory'),
readThemes = require('../../server/utils/read-themes'),
gravatar = require('../../server/utils/gravatar'),
tmp = require('tmp'),
utils = require('../../server/utils'),
join = require('path').join,
fs = require('fs');
utils = require('../../server/utils');
// To stop jshint complaining
should.equal(true, true);
@ -367,16 +368,12 @@ describe('Server Utilities', function () {
});
describe('gravatar-lookup', function () {
var currentEnv = process.env.NODE_ENV;
beforeEach(function () {
// give environment a value that will call gravatar
process.env.NODE_ENV = 'production';
configUtils.set('env', 'production');
});
afterEach(function () {
// reset the environment
process.env.NODE_ENV = currentEnv;
configUtils.restore();
});
it('can successfully lookup a gravatar url', function (done) {

View file

@ -8,9 +8,7 @@ var _ = require('lodash'),
configUtils = require('../utils/configUtils'),
xmlrpc = rewire('../../server/data/xml/xmlrpc'),
events = require('../../server/events'),
logging = require('../../server/logging'),
// storing current environment
currentEnv = process.env.NODE_ENV;
logging = require('../../server/logging');
// To stop jshint complaining
should.equal(true, true);
@ -21,16 +19,14 @@ describe('XMLRPC', function () {
beforeEach(function () {
sandbox = sinon.sandbox.create();
eventStub = sandbox.stub(events, 'on');
// give environment a value that will ping
process.env.NODE_ENV = 'production';
configUtils.set('env', 'production');
});
afterEach(function () {
sandbox.restore();
configUtils.restore();
nock.cleanAll();
// reset the environment
process.env.NODE_ENV = currentEnv;
});
it('listen() should initialise event correctly', function () {