diff --git a/conf/default.conf.js b/conf/default.conf.js index b24fee5..896f58e 100644 --- a/conf/default.conf.js +++ b/conf/default.conf.js @@ -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 */ @@ -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: '' diff --git a/conf/index.js b/conf/index.js index 0a30da2..4b0254e 100644 --- a/conf/index.js +++ b/conf/index.js @@ -1,6 +1,7 @@ /** * red configuration for different environment. */ +var _ = require('lodash'); /** * export configurations. @@ -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'); diff --git a/package.json b/package.json index 1c163fb..00ad8f7 100644 --- a/package.json +++ b/package.json @@ -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",