Skip to content

Commit

Permalink
update /conf, no need to always require the config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Yang committed May 11, 2015
1 parent b3351f9 commit 3610483
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
27 changes: 18 additions & 9 deletions conf/default.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ var env = process.env;
var MONGO_HOST = env.MONGODB_HOST ? (env.MONGODB_HOST + ':' + (env.MONGODB_PORT || 27017)) : null;
var ARR_SPLITTER = /\s*,\s*/g;

function getDoubanMore() {
var ret = [];
if (env.DOUBAN_APP_MORE) {
ret = DOUBAN_APP_MORE.trim().split(ARR_SPLITTER).map(function(item, i) {
var tmp = item.split(':');
return {
key: tmp[0],
secret: tmp[1],
limit: DOUBAN_APP_MORE_LIMIT || 10
}
});
}
return ret;
}

/**
* some default settings
*/
Expand Down Expand Up @@ -44,17 +59,11 @@ module.exports = {

douban: {
limit: env.DOUBAN_APP_LIMIT || 10, // request limit per minute
key: env.DOUBAN_APP_KEY || '',
secret: env.DOUBAN_APP_SECRET || ''
key: env.DOUBAN_APP_KEY || 'my',
secret: env.DOUBAN_APP_SECRET || 'god'
},
// more random api keys for public informations
douban_more: [
{
limit: env.DOUBAN_APP_MORE_LIMIT || 10,
key: env.DOUBAN_APP_MORE_KEY || '',
secret: env.DOUBAN_APP_MORE_SECRET || ''
},
],
douban_more: getDoubanMore(),

// google analytics id
ga_id: ''
Expand Down
10 changes: 8 additions & 2 deletions conf/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* red configuration for different environment.
*/
var _ = require('lodash');

/**
* export configurations.
Expand All @@ -14,9 +15,14 @@ module.exports = readConfig();
function readConfig() {
var NODE_ENV = global.process.env.NODE_ENV || 'development';
var defaultConf = require('./default.conf.js');
var conf = require('./' + NODE_ENV + '.conf.js');
var conf = {};

conf.__proto__ = defaultConf;
try {
// load from $NODE_ENV.conf.js file
conf = require('./' + NODE_ENV + '.conf.js');
} catch (e) {}

conf = _.merge(conf, defaultConf);

removeTailingSlash(conf, 'assets_root');
removeTailingSlash(conf, 'site_root');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"debug": "~0.7.2",
"raven": "~0.5.0",
"strftime": "~0.6.2",
"lodash": "~2.4.1",
"lodash": "~3.8.0",
"batch-stream2": "~0.1.3",
"moment": "~2.2.1",
"redis": "~0.8.2",
Expand Down

0 comments on commit 3610483

Please sign in to comment.