-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.js
79 lines (59 loc) · 1.91 KB
/
configuration.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
require("dotenv-flow").config()
const fs = require("fs")
const merge = require("deepmerge")
const defaultConfig = require("./config_default.json")
let config
const configPath = process.env.CONFIG_PATH || "./config.json"
if (fs.existsSync(configPath)) {
const result = fs.readFileSync(configPath)
config = JSON.parse(result)
if (!config.port) {
config.port = defaultConfig.port
}
config.rateLimit = merge(defaultConfig.rateLimit, config.rateLimit || {})
config.apiKeys = merge(defaultConfig.apiKeys, config.apiKeys || [])
config.remoteKeys = merge(defaultConfig.remoteKeys, config.remoteKeys || {})
config.check = merge(defaultConfig.check, config.check || {})
config.node = merge(defaultConfig.node, config.node || {})
config.logs = merge(defaultConfig.logs, config.logs || {})
if (!config.methods?.length) config.methods = defaultConfig.methods
if (!config.cache) config.cache = defaultConfig.cache
} else {
config = defaultConfig
}
// support old env variables
if (process.env.PORT) {
config.port = process.env.PORT
}
if (process.env.AVAILABLE_KEYS) {
config.apiKeys = JSON.parse(process.env.AVAILABLE_KEYS)
}
if (process.env.REMOTE_KEYS_ENABLED) {
config.remoteKeys.enabled = !!+process.env.REMOTE_KEYS_ENABLED
}
if (process.env.REMOTE_KEYS_URL) {
config.remoteKeys.url = process.env.REMOTE_KEYS_URL
}
if (process.env.REMOTE_KEYS_AUTH) {
config.remoteKeys.authorization = process.env.REMOTE_KEYS_AUTH
}
if (process.env.GOD_API_KEY) {
config.godApiKey = process.env.GOD_API_KEY
}
if (process.env.IDENA_URL) {
config.node.url = process.env.IDENA_URL
}
if (process.env.IDENA_KEY) {
config.node.key = process.env.IDENA_KEY
}
if (process.env.LOGS_OUTPUT) {
config.logs.output = process.env.LOGS_OUTPUT
}
if (process.env.MARKETPLACE_ADDR) {
config.marketplaceAddr = process.env.MARKETPLACE_ADDR
}
// print config
if (process.env.PRINT_CONFIG) {
console.log(config)
}
module.exports = config