forked from fudong1127/insight-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
133 lines (115 loc) · 3.92 KB
/
config.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use strict';
var path = require('path');
var fs = require('fs');
var mkdirp = require('mkdirp');
var rootPath = path.normalize(__dirname + '/..'),
env,
db,
port,
b_port,
p2p_port;
var packageStr = fs.readFileSync(rootPath + '/package.json');
var version = JSON.parse(packageStr).version;
function getUserHome() {
return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
}
var home = process.env.INSIGHT_DB || (getUserHome() + '/.insight');
if (process.env.INSIGHT_NETWORK === 'livenet') {
env = 'livenet';
db = home;
port = '3000';
b_port = '8332';
p2p_port = '8333';
} else {
env = 'testnet';
db = home + '/testnet';
port = '3001';
b_port = '18332';
p2p_port = '18333';
}
port = parseInt(process.env.INSIGHT_PORT) || port;
switch (process.env.NODE_ENV) {
case 'production':
env += '';
break;
case 'test':
env += ' - test environment';
break;
default:
env += ' - development';
break;
}
var network = process.env.INSIGHT_NETWORK || 'testnet';
var dataDir = process.env.BITCOIND_DATADIR;
var isWin = /^win/.test(process.platform);
var isMac = /^darwin/.test(process.platform);
var isLinux = /^linux/.test(process.platform);
if (!dataDir) {
if (isWin) dataDir = '%APPDATA%\\Bitcoin\\';
if (isMac) dataDir = process.env.HOME + '/Library/Application Support/Bitcoin/';
if (isLinux) dataDir = process.env.HOME + '/.bitcoin/';
}
dataDir += network === 'testnet' ? 'testnet3' : '';
var safeConfirmations = process.env.INSIGHT_SAFE_CONFIRMATIONS || 6;
var ignoreCache = process.env.INSIGHT_IGNORE_CACHE || 0;
var bitcoindConf = {
protocol: process.env.BITCOIND_PROTO || 'http',
user: process.env.BITCOIND_USER || 'user',
pass: process.env.BITCOIND_PASS || 'pass',
host: process.env.BITCOIND_HOST || '127.0.0.1',
port: process.env.BITCOIND_PORT || b_port,
p2pPort: process.env.BITCOIND_P2P_PORT || p2p_port,
p2pHost: process.env.BITCOIND_P2P_HOST || process.env.BITCOIND_HOST || '127.0.0.1',
dataDir: dataDir,
// DO NOT CHANGE THIS!
disableAgent: true
};
var enableMonitor = process.env.ENABLE_MONITOR === 'true';
var enableCleaner = process.env.ENABLE_CLEANER === 'true';
var enableMailbox = process.env.ENABLE_MAILBOX === 'true';
var enableRatelimiter = process.env.ENABLE_RATELIMITER === 'true';
var enableCredentialstore = process.env.ENABLE_CREDSTORE === 'true';
var enableEmailstore = process.env.ENABLE_EMAILSTORE === 'true';
var enablePublicInfo = process.env.ENABLE_PUBLICINFO === 'true';
var loggerLevel = process.env.LOGGER_LEVEL || 'info';
var enableHTTPS = process.env.ENABLE_HTTPS === 'true';
if (!fs.existsSync(db)) {
mkdirp.sync(db);
}
module.exports = {
enableMonitor: enableMonitor,
monitor: require('../plugins/config-monitor.js'),
enableCleaner: enableCleaner,
cleaner: require('../plugins/config-cleaner.js'),
enableMailbox: enableMailbox,
mailbox: require('../plugins/config-mailbox.js'),
enableRatelimiter: enableRatelimiter,
ratelimiter: require('../plugins/config-ratelimiter.js'),
enableCredentialstore: enableCredentialstore,
credentialstore: require('../plugins/config-credentialstore'),
enableEmailstore: enableEmailstore,
emailstore: require('../plugins/config-emailstore'),
enablePublicInfo: enablePublicInfo,
publicInfo: require('../plugins/publicInfo/config'),
loggerLevel: loggerLevel,
enableHTTPS: enableHTTPS,
version: version,
root: rootPath,
publicPath: process.env.INSIGHT_PUBLIC_PATH || false,
appName: 'Insight ' + env,
apiPrefix: '/api',
port: port,
leveldb: db,
bitcoind: bitcoindConf,
network: network,
disableP2pSync: false,
disableHistoricSync: false,
poolMatchFile: rootPath + '/etc/minersPoolStrings.json',
// Time to refresh the currency rate. In minutes
currencyRefresh: 10,
keys: {
segmentio: process.env.INSIGHT_SEGMENTIO_KEY
},
safeConfirmations: safeConfirmations, // PLEASE NOTE THAT *FULL RESYNC* IS NEEDED TO CHANGE safeConfirmations
ignoreCache: ignoreCache,
};