-
Notifications
You must be signed in to change notification settings - Fork 63
/
config.js
93 lines (81 loc) · 2.67 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
const AV = require('leancloud-storage')
const { setClientGlobalVar, setClientGlobalVars } = require('./clientGlobalVar')
let host
switch (process.env.LEANCLOUD_APP_ENV) {
case 'production':
host = process.env.TICKET_HOST
break
case 'stage':
host = process.env.TICKET_HOST_STG
break
case 'development':
default:
host = 'http://localhost:' + process.env.LEANCLOUD_APP_PORT
}
function getCORSOrigin() {
if (!process.env.CORS_ORIGIN) {
return false
}
const origins = process.env.CORS_ORIGIN.split(',').map((origin) => {
if (/^\/.*\/$/.test(origin)) {
return new RegExp(origin.slice(1, -1))
} else {
return origin
}
})
return origins.length > 1 ? origins : origins[0]
}
/**
*
* @param {string} key
* @returns {Promise<any | null>}
*/
async function getConfigValue(key) {
const query = new AV.Query('Config')
query.equalTo('key', key)
const obj = await query.first({ useMasterKey: true })
return obj?.get('value') ?? null
}
const allowMutateEvaluation = !!process.env.ALLOW_MUTATE_EVALUATION
module.exports = {
host,
oauthKey: process.env.OAUTH_KEY,
oauthSecret: process.env.OAUTH_SECRET,
enableLeanCloudIntegration: process.env.ENABLE_LEANCLOUD_INTEGRATION,
leancloudAppUrl: process.env.LEANCLOUD_APP_URL,
sentryDSN: process.env.SENTRY_API_DSN,
sentryDSNPublic: process.env.SENTRY_WEB_DSN,
allowMutateEvaluation,
corsOrigin: getCORSOrigin(),
getConfigValue,
}
const integrations = []
const zulip = require('./integrations/zulip/server')
if (process.env.ZULIP_API_KEY) {
const zulipConfig = {
username: process.env.ZULIP_USERNAME,
apiKey: process.env.ZULIP_API_KEY,
realm: process.env.ZULIP_REALM,
stream: process.env.ZULIP_STREAM,
topic: process.env.ZULIP_TOPIC,
}
integrations.push(zulip(zulipConfig))
}
module.exports.integrations = integrations
setClientGlobalVars({
INTEGRATIONS: integrations.map((t) => t.name),
ENABLE_LEANCLOUD_INTEGRATION: !!process.env.ENABLE_LEANCLOUD_INTEGRATION,
LEANCLOUD_APP_ID: process.env.LEANCLOUD_APP_ID,
LEANCLOUD_APP_KEY: process.env.LEANCLOUD_APP_KEY,
LEANCLOUD_API_HOST: process.env.LEANCLOUD_API_HOST,
LEANCLOUD_APP_ENV: process.env.LEANCLOUD_APP_ENV,
LEANCLOUD_OAUTH_REGION: process.env.LEANCLOUD_REGION == 'US' ? 'us-w1' : 'cn-n1',
// Use HELP_EMAIL instead of SUPPORT_EMAIL, because there is a bug in LeanEngine.
// See #1830 of LeanEngine repo (private) for more information.
SUPPORT_EMAIL: process.env.HELP_EMAIL,
ALLOW_MUTATE_EVALUATION: allowMutateEvaluation,
ENABLE_XD_OAUTH: !!process.env.ENABLE_XD_OAUTH,
})
getConfigValue('gravatar_url')
.then((url) => url && setClientGlobalVar('GRAVATAR_URL', url))
.catch(console.error)