2014-01-06 08:33:58 -08:00
'use strict' ;
2014-01-31 09:20:56 -08:00
var path = require ( 'path' ) ,
2014-04-17 05:32:49 -07:00
fs = require ( 'fs' ) ,
2014-01-31 10:00:48 -08:00
rootPath = path . normalize ( _ _dirname + '/..' ) ,
2014-02-11 11:30:58 -08:00
env ,
2014-02-13 08:16:41 -08:00
db ,
port ,
b _port ,
p2p _port ;
2014-05-26 09:29:52 -07:00
var packageStr = fs . readFileSync ( 'package.json' ) ;
var version = JSON . parse ( packageStr ) . version ;
2014-04-17 05:32:49 -07:00
function getUserHome ( ) {
return process . env [ ( process . platform == 'win32' ) ? 'USERPROFILE' : 'HOME' ] ;
}
2014-04-17 05:46:19 -07:00
var home = process . env . INSIGHT _DB || ( getUserHome ( ) + '/.insight' ) ;
2014-04-17 05:32:49 -07:00
2014-02-13 08:16:41 -08:00
if ( process . env . INSIGHT _NETWORK === 'livenet' ) {
env = 'livenet' ;
2014-04-17 05:32:49 -07:00
db = home ;
2014-02-13 08:20:19 -08:00
port = '3000' ;
2014-02-13 08:16:41 -08:00
b _port = '8332' ;
p2p _port = '8333' ;
}
else {
env = 'testnet' ;
2014-04-17 05:32:49 -07:00
db = home + '/testnet' ;
2014-02-26 07:05:30 -08:00
port = '3001' ;
b _port = '18332' ;
2014-02-13 08:16:41 -08:00
p2p _port = '18333' ;
}
2014-01-31 10:00:48 -08:00
2014-05-13 10:02:19 -07:00
2014-01-31 10:00:48 -08:00
switch ( process . env . NODE _ENV ) {
case 'production' :
2014-02-13 08:16:41 -08:00
env += '' ;
2014-02-11 11:30:58 -08:00
break ;
2014-01-31 10:00:48 -08:00
case 'test' :
2014-02-13 08:16:41 -08:00
env += ' - test environment' ;
2014-02-11 11:30:58 -08:00
break ;
2014-01-31 10:00:48 -08:00
default :
2014-02-13 08:16:41 -08:00
env += ' - development' ;
2014-02-11 11:30:58 -08:00
break ;
2014-01-31 10:00:48 -08:00
}
2014-02-11 11:30:58 -08:00
2014-02-25 06:10:00 -08:00
var network = process . env . INSIGHT _NETWORK || 'testnet' ;
2014-02-11 13:18:01 -08:00
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/' ;
}
2014-02-25 06:10:00 -08:00
dataDir += network === 'testnet' ? 'testnet3' : '' ;
2014-02-11 13:18:01 -08:00
2014-05-26 09:29:52 -07:00
var safeConfirmations = process . env . SAFE _CONFIRMATIONS || 6 ;
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 ,
dataDir : dataDir ,
// DO NOT CHANGE THIS!
disableAgent : true
} ;
/*jshint multistr: true */
console . log (
2014-05-26 09:47:35 -07:00
' \ n \
_ _ _ _ _ _ _ _ _ _ _ _ _ \ n \
/ _ / _ _ _ _ _ _ _ _ ( _ ) _ _ _ _ / / _ / / _ / | _ _ _ _ ( _ ) \ n \
/ / / _ _ \ \ / _ _ _ / / __ `/ _ _ \ \ / _ _ / / / \ | \ | / __ \\/ / \ n \
_ / // / / (__ ) / /_/ / / / / /_ / ___ |/ /_/ / / \n\
/ _ _ _ / _ / / _ / _ _ _ _ / _ / \ \ _ _ , / _ / / _ / \ \ _ _ / / _ / | _ / . _ _ _ / _ / \ n \
/____/ / _ / \ n \
\ n \ t \ t \ t \ t \ t \ tv % s \ n \
# Configuration : \ n \
2014-05-26 09:29:52 -07:00
\ t \ tNetwork : % s \ tINSIGHT _NETWORK \ n \
\ t \ tDatabase Path : % s \ tINSIGHT _DB \ n \
\ t \ tSafe Confirmations : % s \ tSAFE _CONFIRMATIONS \ n \
# Bicoind Connection configuration : \ n \
\ t \ tRPC Username : % s \ tBITCOIND _USER \ n \
\ t \ tRPC Password : % s \ tBITCOIND _PASS \ n \
\ t \ tRPC Protocol : % s \ tBITCOIND _PROTO \ n \
\ t \ tRPC Host : % s \ tBITCOIND _HOST \ n \
\ t \ tRPC Port : % s \ tBITCOIND _PORT \ n \
\ t \ tP2P Port : % s \ tBITCOIND _P2P _PORT \ n \
\ t \ tData Dir : % s \ tBITCOIND _DATADIR \ n \
2014-05-26 09:47:35 -07:00
\ t \ t % s \ n \
2014-05-26 09:29:52 -07:00
\ nChange setting by assigning the enviroment variables in the last column . Example : \ n \
$ INSIGHT _NETWORK = "testnet" BITCOIND _HOST = "123.123.123.123" . / insight . js \
\ n \ n ' ,
version ,
network , home , safeConfirmations ,
bitcoindConf . user ,
bitcoindConf . pass ? 'Yes(hidden)' : 'No' ,
bitcoindConf . protocol ,
bitcoindConf . host ,
bitcoindConf . port ,
bitcoindConf . p2p _port ,
2014-05-26 09:47:35 -07:00
dataDir + ( network === 'testnet' ? '*' : '' ) ,
( network === 'testnet' ? '* (/testnet3 is added automatically)' : '' )
2014-05-26 09:29:52 -07:00
) ;
2014-04-17 05:32:49 -07:00
if ( ! fs . existsSync ( db ) ) {
console . log ( '## ERROR ##\n\tDB Directory "%s" not found. \n\tCreate it, move your old DB there or set the INSIGHT_DB environment variable.\n\tNOTE: In older insight-api versions, db was stored at <insight-root>/db' , db ) ;
process . exit ( - 1 ) ;
}
2014-01-31 09:20:56 -08:00
module . exports = {
root : rootPath ,
2014-02-26 11:27:22 -08:00
publicPath : process . env . INSIGHT _PUBLIC _PATH || false ,
2014-01-31 10:00:48 -08:00
appName : 'Insight ' + env ,
2014-02-24 20:44:19 -08:00
apiPrefix : '/api' ,
2014-02-11 11:30:58 -08:00
port : port ,
leveldb : db ,
2014-05-26 09:29:52 -07:00
bitcoind : bitcoindConf ,
2014-02-25 06:10:00 -08:00
network : network ,
2014-01-31 09:20:56 -08:00
disableP2pSync : false ,
disableHistoricSync : false ,
2014-02-26 11:27:22 -08:00
poolMatchFile : rootPath + '/etc/minersPoolStrings.json' ,
2014-02-05 10:59:44 -08:00
// Time to refresh the currency rate. In minutes
2014-02-26 07:05:30 -08:00
currencyRefresh : 10 ,
keys : {
2014-02-26 11:27:22 -08:00
segmentio : process . env . INSIGHT _SEGMENTIO _KEY
2014-05-25 13:34:49 -07:00
} ,
2014-05-26 09:29:52 -07:00
safeConfirmations : safeConfirmations , // PLEASE NOTE THAT *FULL RESYNC* IS NEEDED TO CHANGE safeConfirmations
2014-01-31 09:20:56 -08:00
} ;