提交 6033314756b57ade03dda320dc31b39e50617690
Merge pull request #16 from BrunoBernardino/master
Allow boot/local.js file
正在显示
2 个修改的文件
包含
51 行增加
和
5 行删除
... | ... | @@ -87,6 +87,41 @@ exports['@singleton'] = true |
87 | 87 | |
88 | 88 | ``` |
89 | 89 | |
90 | +You can have a `boot/local.js` with local settings if you need something unversioned (and load it by doing `$ export NODE_ENV=local`). | |
91 | + | |
92 | +```js | |
93 | +// boot/local.js | |
94 | + | |
95 | +var path = require('path') | |
96 | +var uploadsDir = path.join(__dirname, '..', 'uploads') | |
97 | +var maxAge = 30 * 24 * 60 * 60 * 1000 | |
98 | + | |
99 | +exports = module.exports = function() { | |
100 | + | |
101 | + return { | |
102 | + local: { | |
103 | + uploadsDir: uploadsDir, | |
104 | + server: { | |
105 | + host: '0.0.0.0', | |
106 | + env: 'local', | |
107 | + port: 3003, | |
108 | + }, | |
109 | + mongo: { | |
110 | + dbname: 'igloo-local', | |
111 | + }, | |
112 | + redis: { | |
113 | + prefix: 'igloo-local', | |
114 | + maxAge: maxAge | |
115 | + } | |
116 | + } | |
117 | + | |
118 | + } | |
119 | + | |
120 | +} | |
121 | + | |
122 | +exports['@singleton'] = true | |
123 | +``` | |
124 | + | |
90 | 125 | |
91 | 126 | ```js |
92 | 127 | // app.js | ... | ... |
... | ... | @@ -11,17 +11,28 @@ exports = module.exports = function(config, local) { |
11 | 11 | |
12 | 12 | var env = process.env.NODE_ENV || 'development' |
13 | 13 | |
14 | - if (!_.isObject(config[env])) | |
15 | - throw new Error(util.format('Unknown environment %s', env)) | |
16 | - | |
17 | 14 | if (!_.isObject(local)) |
18 | 15 | local = {} |
19 | 16 | |
20 | - mergeDefaults(settings, local, config[env], config.defaults) | |
17 | + mergeDefaults(config, local) | |
18 | + | |
19 | + if (!_.isObject(config[env])) | |
20 | + throw new Error(util.format('Unknown environment %s', env)) | |
21 | + | |
22 | + mergeDefaults(settings, config[env], config.defaults) | |
21 | 23 | |
22 | 24 | return settings |
23 | 25 | |
24 | 26 | } |
25 | 27 | |
26 | 28 | exports['@singleton'] = true |
27 | -exports['@require'] = [ 'config' ] | |
29 | +exports['@require'] = ['config'] | |
30 | + | |
31 | +var fs = require('fs') | |
32 | +var path = require('path') | |
33 | +var localPath = path.join(__dirname, '..', '..', '..', '..' ,'boot', 'local.js') | |
34 | + | |
35 | +// Include local.js if it exists at boot/local.js | |
36 | +if (fs.existsSync(localPath)) { | |
37 | + exports['@require'].push('local') | |
38 | +} | ... | ... |
请
注册
或
登录
后发表评论