-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathconfig.js
155 lines (134 loc) · 4.13 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* jshint asi: true, node: true, laxbreak: true, laxcomma: true, undef: true, unused: true, esversion: 6 */
import fs from 'fs'
import { getCurrent } from './eyeshade/migrations/current.js';
import url from 'url';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
let referrals;
let postgres;
let postgresRO;
const services = {
eyeshade: {
portno: 3002,
f: () => {
referrals =
{
currency: process.env.REFERRALS_CURRENCY || 'USD',
amount: process.env.REFERRALS_AMOUNT || 5
}
postgres =
{
connectionString: process.env.DATABASE_URL || 'postgres://localhost/test',
schemaVersion: getCurrent(),
schemaVersionCheck: true,
ssl: process.env.NODE_ENV === 'production' ? { ca: fs.readFileSync(process.env.RDS_CA_CERT_LOCATION).toString(), rejectUnauthorized: true } : false
}
postgresRO =
{
connectionString: process.env.DATABASE_RO_URL || 'postgres://localhost/test',
ssl: process.env.NODE_ENV === 'production' ? { ca: fs.readFileSync(process.env.RDS_CA_CERT_LOCATION).toString(), rejectUnauthorized: true } : false
}
}
}
}
const service = services[process.env.SERVICE]
if (!service) {
throw new Error('invalid process.env.SERVICE=' + process.env.SERVICE)
}
process.env.PORT = process.env.PORT || service.portno
const redisURL = process.env.REDIS_URL
if (!process.env.PUBLISHERS_URL) throw new Error("Need PUBLISHERS_URL");
if (!process.env.PUBLISHERS_TOKEN) throw new Error("Need PUBLISHERS_TOKEN");
const altcurrency = process.env.ALTCURRENCY || 'BAT';
const publishers = {
url : process.env.PUBLISHERS_URL,
access_token : process.env.PUBLISHERS_TOKEN
};
const cache =
{
redis:
{ url: redisURL || 'redis://localhost:6379' }
};
// const currency =
// {
// altcoins: process.env.CRYPTO_CURRENCIES ? process.env.CRYPTO_CURRENCIES.split(',')
// : ['BAT', 'BTC', 'ETH', 'LTC']
// };
const login = { github: false };
const sentry =
{
dsn: process.env.SENTRY_DSN || false,
slug: process.env.HEROKU_SLUG_COMMIT || 'test',
project: process.env.HEROKU_APP_NAME || process.env.SERVICE
};
const newrelic = {
key: process.env.NEW_RELIC_LICENSE_KEY ||
false
};
// wallet: {},
const testingCohorts = process.env.TESTING_COHORTS ? process.env.TESTING_COHORTS.split(',') : [];
const currency =
{
url: process.env.BAT_RATIOS_URL || false,
access_token: process.env.BAT_RATIOS_TOKEN || false
};
if (service.f) service.f()
let server;
if (process.env.NODE_ENV === 'production') {
server = url.parse('https://' + process.env.HOST)
} else {
server = url.parse('http://' + '127.0.0.1' + ':' + process.env.PORT)
}
let wallet = {};
if (process.env.BAT_SETTLEMENT_ADDRESS) {
wallet.settlementAddress =
{ BAT: process.env.BAT_SETTLEMENT_ADDRESS || '0x7c31560552170ce96c4a7b018e93cddc19dc61b6' }
}
if (process.env.BAT_ADS_PAYOUT_ADDRESS) {
wallet.adsPayoutAddress =
{ BAT: process.env.BAT_ADS_PAYOUT_ADDRESS || '0x7c31560552170ce96c4a7b018e93cddc19dc61b6' }
}
let kafka;
if (process.env.KAFKA_BROKERS) {
const kafkaOptions = {
brokers: process.env.KAFKA_BROKERS.split(','),
clientId: process.env.ENV + '.' + process.env.SERVICE,
acks: +process.env.KAFKA_REQUIRED_ACKS
}
kafkaOptions.ssl = {
key: fs.readFileSync(process.env.KAFKA_SSL_KEY_LOCATION, 'utf-8'),
cert: fs.readFileSync(process.env.KAFKA_SSL_CERTIFICATE_LOCATION, 'utf-8')
}
if (process.env.KAFKA_SSL_CA_LOCATION) {
kafkaOptions.ssl.ca = [fs.readFileSync(process.env.KAFKA_SSL_CA_LOCATION, 'utf-8')]
}
if (process.env.KAFKA_SSL_KEY_PASSWORD) {
kafkaOptions.ssl.passphrase = process.env.KAFKA_SSL_KEY_PASSWORD
}
kafka = { ...kafkaOptions }
}
const prometheus =
{
label: process.env.SERVICE + '.' + (process.env.DYNO || 1),
redis: redisURL || false
}
export default {
kafka,
prometheus,
server,
wallet,
altcurrency,
publishers,
currency,
testingCohorts,
newrelic,
sentry,
login,
cache,
service,
referrals,
postgres,
postgresRO
}