forked from mozilla/firehug
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathshared.js
More file actions
47 lines (40 loc) · 1.33 KB
/
shared.js
File metadata and controls
47 lines (40 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// all the environments
var env = require( 'nconf' ).argv()
.env()
.file( { file: 'local.json' } )
.defaults({
'JOB_SCHEDULE': '*/5 * * * *',
'REDIS_PREFIX': 'firehug',
'EVENT_TIMEZONE': 'Europe/London',
'SPLASH': true,
'PORT': 5000
});
// setup debugging
var debug = require( 'debug' );
process.env.DEBUG_COLORS = true;
debug.enable( env.get( 'DEBUG' ) );
debug.useColors();
// get redis client
var redis = require( 'redis' );
function getRedisClient() {
var redisConf = {};
var db = {};
if( env.get( 'VCAP_SERVICES' ) ) {
redisConf = JSON.parse( env.get( 'VCAP_SERVICES' ).redis[ 0 ].credentials );
db = redis.createClient( redisConf.port, redisConf.host );
return db;
}
if( env.get( 'REDISTOGO_URL' ) ) {
redisConf = require( 'url' ).parse( env.get( 'REDISTOGO_URL' ) );
db = redis.createClient( redisConf.port, redisConf.hostname );
db.auth( redisConf.auth.split( ':' )[ 1 ] );
return db;
}
return redis.createClient();
}
module.exports = {
env: env,
nconf: env, // legacy support to be removed.
debug: debug,
redisClient: getRedisClient()
};