2021-03-24 19:21:23 +01:00
|
|
|
function isTest() {
|
|
|
|
return (
|
|
|
|
process.env.NODE_ENV === "jest" ||
|
|
|
|
process.env.NODE_ENV === "cypress" ||
|
2022-01-28 16:43:51 +01:00
|
|
|
(process.env.JEST_WORKER_ID != null &&
|
|
|
|
process.env.JEST_WORKER_ID !== "null")
|
2021-03-24 19:21:23 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-03-23 16:37:11 +01:00
|
|
|
function isDev() {
|
|
|
|
return (
|
|
|
|
process.env.NODE_ENV !== "production" &&
|
2021-03-24 19:21:23 +01:00
|
|
|
process.env.BUDIBASE_ENVIRONMENT !== "production"
|
2021-03-23 16:37:11 +01:00
|
|
|
)
|
|
|
|
}
|
2020-10-26 18:49:33 +01:00
|
|
|
|
2021-09-29 19:22:56 +02:00
|
|
|
function isCypress() {
|
|
|
|
return process.env.NODE_ENV === "cypress"
|
|
|
|
}
|
|
|
|
|
2020-10-26 18:49:33 +01:00
|
|
|
let LOADED = false
|
2021-03-24 19:21:23 +01:00
|
|
|
if (!LOADED && isDev() && !isTest()) {
|
2021-03-23 16:37:11 +01:00
|
|
|
require("dotenv").config()
|
2020-10-26 18:49:33 +01:00
|
|
|
LOADED = true
|
|
|
|
}
|
|
|
|
|
2022-04-08 16:17:19 +02:00
|
|
|
function parseIntSafe(number) {
|
|
|
|
if (number) {
|
|
|
|
return parseInt(number)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-22 18:42:41 +01:00
|
|
|
let inThread = false
|
|
|
|
|
2020-05-14 16:12:30 +02:00
|
|
|
module.exports = {
|
2021-03-23 16:37:11 +01:00
|
|
|
// important
|
2020-05-14 16:12:30 +02:00
|
|
|
PORT: process.env.PORT,
|
2021-03-23 16:37:11 +01:00
|
|
|
JWT_SECRET: process.env.JWT_SECRET,
|
2020-05-14 16:12:30 +02:00
|
|
|
COUCH_DB_URL: process.env.COUCH_DB_URL,
|
2021-03-23 16:37:11 +01:00
|
|
|
MINIO_URL: process.env.MINIO_URL,
|
|
|
|
WORKER_URL: process.env.WORKER_URL,
|
2021-09-21 18:37:26 +02:00
|
|
|
SELF_HOSTED: process.env.SELF_HOSTED,
|
2021-03-23 16:37:11 +01:00
|
|
|
AWS_REGION: process.env.AWS_REGION,
|
|
|
|
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
|
2021-03-24 13:54:59 +01:00
|
|
|
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
|
|
|
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
2021-03-24 19:21:23 +01:00
|
|
|
USE_QUOTAS: process.env.USE_QUOTAS,
|
2022-01-17 13:44:53 +01:00
|
|
|
EXCLUDE_QUOTAS_TENANTS: process.env.EXCLUDE_QUOTAS_TENANTS,
|
2021-04-27 18:29:05 +02:00
|
|
|
REDIS_URL: process.env.REDIS_URL,
|
|
|
|
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
2021-05-11 16:23:03 +02:00
|
|
|
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
|
2021-08-05 10:59:08 +02:00
|
|
|
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
2022-01-24 11:48:59 +01:00
|
|
|
HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS,
|
2022-03-03 13:03:29 +01:00
|
|
|
API_REQ_LIMIT_PER_SEC: process.env.API_REQ_LIMIT_PER_SEC,
|
2022-03-28 17:44:33 +02:00
|
|
|
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
|
|
|
|
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
|
2021-03-23 16:37:11 +01:00
|
|
|
// environment
|
|
|
|
NODE_ENV: process.env.NODE_ENV,
|
|
|
|
JEST_WORKER_ID: process.env.JEST_WORKER_ID,
|
|
|
|
BUDIBASE_ENVIRONMENT: process.env.BUDIBASE_ENVIRONMENT,
|
2021-09-29 17:55:59 +02:00
|
|
|
DISABLE_ACCOUNT_PORTAL: process.env.DISABLE_ACCOUNT_PORTAL,
|
2021-03-23 16:37:11 +01:00
|
|
|
// minor
|
2020-05-14 16:12:30 +02:00
|
|
|
SALT_ROUNDS: process.env.SALT_ROUNDS,
|
|
|
|
LOGGER: process.env.LOGGER,
|
2020-10-28 21:35:06 +01:00
|
|
|
LOG_LEVEL: process.env.LOG_LEVEL,
|
2020-09-18 17:50:52 +02:00
|
|
|
AUTOMATION_DIRECTORY: process.env.AUTOMATION_DIRECTORY,
|
|
|
|
AUTOMATION_BUCKET: process.env.AUTOMATION_BUCKET,
|
2020-09-18 14:51:56 +02:00
|
|
|
SENDGRID_API_KEY: process.env.SENDGRID_API_KEY,
|
2020-10-06 20:13:41 +02:00
|
|
|
DYNAMO_ENDPOINT: process.env.DYNAMO_ENDPOINT,
|
2021-09-30 16:03:57 +02:00
|
|
|
POSTHOG_TOKEN: process.env.POSTHOG_TOKEN,
|
2021-03-23 16:37:11 +01:00
|
|
|
// old - to remove
|
|
|
|
CLIENT_ID: process.env.CLIENT_ID,
|
|
|
|
BUDIBASE_DIR: process.env.BUDIBASE_DIR,
|
2020-10-28 21:35:06 +01:00
|
|
|
DEPLOYMENT_DB_URL: process.env.DEPLOYMENT_DB_URL,
|
2021-03-22 17:39:11 +01:00
|
|
|
BUDIBASE_API_KEY: process.env.BUDIBASE_API_KEY,
|
|
|
|
USERID_API_KEY: process.env.USERID_API_KEY,
|
|
|
|
DEPLOYMENT_CREDENTIALS_URL: process.env.DEPLOYMENT_CREDENTIALS_URL,
|
2021-09-14 12:18:02 +02:00
|
|
|
ALLOW_DEV_AUTOMATIONS: process.env.ALLOW_DEV_AUTOMATIONS,
|
2021-11-22 18:42:41 +01:00
|
|
|
DISABLE_THREADING: process.env.DISABLE_THREADING,
|
2022-04-08 16:17:19 +02:00
|
|
|
QUERY_THREAD_TIMEOUT: parseIntSafe(process.env.QUERY_THREAD_TIMEOUT),
|
2022-03-21 18:44:43 +01:00
|
|
|
SQL_MAX_ROWS: process.env.SQL_MAX_ROWS,
|
2020-10-28 21:35:06 +01:00
|
|
|
_set(key, value) {
|
|
|
|
process.env[key] = value
|
2020-10-28 23:24:44 +01:00
|
|
|
module.exports[key] = value
|
2020-10-28 21:35:06 +01:00
|
|
|
},
|
2021-03-24 19:21:23 +01:00
|
|
|
isTest,
|
2021-09-29 19:22:56 +02:00
|
|
|
isCypress,
|
2021-03-23 16:37:11 +01:00
|
|
|
isDev,
|
2021-03-24 19:21:23 +01:00
|
|
|
isProd: () => {
|
|
|
|
return !isDev()
|
|
|
|
},
|
2021-11-22 18:42:41 +01:00
|
|
|
// used to check if already in a thread, don't thread further
|
|
|
|
setInThread: () => {
|
|
|
|
inThread = true
|
|
|
|
},
|
|
|
|
isInThread: () => {
|
|
|
|
return inThread
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// threading can cause memory issues with node-ts in development
|
|
|
|
if (isDev() && module.exports.DISABLE_THREADING == null) {
|
|
|
|
module.exports._set("DISABLE_THREADING", "1")
|
2020-05-14 16:12:30 +02:00
|
|
|
}
|
2021-09-20 19:24:09 +02:00
|
|
|
|
2021-10-11 18:59:44 +02:00
|
|
|
// clean up any environment variable edge cases
|
2021-09-20 19:24:09 +02:00
|
|
|
for (let [key, value] of Object.entries(module.exports)) {
|
2021-10-11 18:59:44 +02:00
|
|
|
// handle the edge case of "0" to disable an environment variable
|
|
|
|
if (value === "0") {
|
|
|
|
module.exports[key] = 0
|
2021-09-20 19:24:09 +02:00
|
|
|
}
|
|
|
|
}
|