-
Notifications
You must be signed in to change notification settings - Fork 13
/
startup.js
44 lines (35 loc) · 981 Bytes
/
startup.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
const { LND, Eclair } = require('./backend')
require('dotenv').config()
const startup = () => {
const requiredKeys = ['LIGESS_USERNAME', 'LIGESS_DOMAIN', 'LIGESS_LN_BACKEND']
checkKeys(requiredKeys)
const backend = process.env.LIGESS_LN_BACKEND
switch (backend) {
case LND:
_lndCheck()
break
case Eclair:
_eclairCheck()
break
}
}
const _lndCheck = () => {
const requiredKeys = ['LIGESS_LND_REST', 'LIGESS_LND_MACAROON']
checkKeys(requiredKeys)
if (!process.env.LIGESS_LND_REST.startsWith('https:')) {
console.error('Env variable LIGESS_LND_REST only supports https protocol')
}
}
const _eclairCheck = () => {
const requiredKeys = ['LIGESS_ECLAIR_REST', 'LIGESS_ECLAIR_PASSWORD']
checkKeys(requiredKeys)
}
const checkKeys = (keys) => {
for (const key of keys) {
if (!process.env[key]) {
console.error(`Env variable ${key} is not defined`)
process.exit(1)
}
}
}
module.exports = { startup }