2023-08-01 11:56:47 +02:00
|
|
|
import { env as coreEnv } from "@budibase/backend-core"
|
|
|
|
import { ServiceType } from "@budibase/types"
|
|
|
|
import { join } from "path"
|
|
|
|
|
|
|
|
coreEnv._set("SERVICE_TYPE", ServiceType.WORKER)
|
2022-05-22 19:29:02 +02:00
|
|
|
|
2021-03-29 16:00:40 +02:00
|
|
|
let LOADED = false
|
2023-09-07 15:37:22 +02:00
|
|
|
if (!LOADED && coreEnv.isDev() && !coreEnv.isTest()) {
|
2022-05-22 19:29:02 +02:00
|
|
|
require("dotenv").config({
|
|
|
|
path: join(__dirname, "..", ".env"),
|
|
|
|
})
|
2021-03-29 16:00:40 +02:00
|
|
|
LOADED = true
|
|
|
|
}
|
|
|
|
|
2022-08-25 20:41:47 +02:00
|
|
|
function parseIntSafe(number: any) {
|
2022-05-23 17:24:29 +02:00
|
|
|
if (number) {
|
|
|
|
return parseInt(number)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-25 20:57:07 +01:00
|
|
|
const environment = {
|
2022-05-17 18:47:33 +02:00
|
|
|
// auth
|
2020-12-16 20:50:02 +01:00
|
|
|
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
|
|
|
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
2024-06-07 17:57:54 +02:00
|
|
|
AWS_SESSION_TOKEN: process.env.AWS_SESSION_TOKEN,
|
2021-03-29 18:31:41 +02:00
|
|
|
SALT_ROUNDS: process.env.SALT_ROUNDS,
|
2021-04-27 18:29:05 +02:00
|
|
|
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
2022-05-17 18:47:33 +02:00
|
|
|
COOKIE_DOMAIN: process.env.COOKIE_DOMAIN,
|
2024-08-08 18:45:04 +02:00
|
|
|
PASSWORD_MIN_LENGTH: process.env.PASSWORD_MIN_LENGTH,
|
2022-05-17 18:47:33 +02:00
|
|
|
// urls
|
|
|
|
MINIO_URL: process.env.MINIO_URL,
|
|
|
|
COUCH_DB_URL: process.env.COUCH_DB_URL,
|
|
|
|
REDIS_URL: process.env.REDIS_URL,
|
|
|
|
ACCOUNT_PORTAL_URL: process.env.ACCOUNT_PORTAL_URL,
|
|
|
|
PLATFORM_URL: process.env.PLATFORM_URL,
|
|
|
|
APPS_URL: process.env.APPS_URL,
|
|
|
|
// ports
|
2022-09-12 16:17:39 +02:00
|
|
|
// prefer worker port to generic port
|
|
|
|
PORT: process.env.WORKER_PORT || process.env.PORT,
|
2022-05-17 18:47:33 +02:00
|
|
|
CLUSTER_PORT: process.env.CLUSTER_PORT,
|
|
|
|
// flags
|
|
|
|
NODE_ENV: process.env.NODE_ENV,
|
2023-02-27 14:42:51 +01:00
|
|
|
SELF_HOSTED: !!parseInt(process.env.SELF_HOSTED || ""),
|
2021-08-05 10:59:08 +02:00
|
|
|
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
2021-09-29 17:55:59 +02:00
|
|
|
DISABLE_ACCOUNT_PORTAL: process.env.DISABLE_ACCOUNT_PORTAL,
|
2021-09-27 23:31:13 +02:00
|
|
|
SMTP_FALLBACK_ENABLED: process.env.SMTP_FALLBACK_ENABLED,
|
2022-05-17 18:47:33 +02:00
|
|
|
DISABLE_DEVELOPER_LICENSE: process.env.DISABLE_DEVELOPER_LICENSE,
|
2024-06-11 13:13:18 +02:00
|
|
|
BUDIBASE_ENVIRONMENT: process.env.BUDIBASE_ENVIRONMENT,
|
2022-05-17 18:47:33 +02:00
|
|
|
// smtp
|
2021-09-27 15:57:22 +02:00
|
|
|
SMTP_USER: process.env.SMTP_USER,
|
|
|
|
SMTP_PASSWORD: process.env.SMTP_PASSWORD,
|
|
|
|
SMTP_HOST: process.env.SMTP_HOST,
|
|
|
|
SMTP_PORT: process.env.SMTP_PORT,
|
|
|
|
SMTP_FROM_ADDRESS: process.env.SMTP_FROM_ADDRESS,
|
2022-05-24 00:43:57 +02:00
|
|
|
// other
|
2022-05-23 18:38:02 +02:00
|
|
|
CHECKLIST_CACHE_TTL: parseIntSafe(process.env.CHECKLIST_CACHE_TTL) || 3600,
|
2022-08-05 18:13:03 +02:00
|
|
|
SESSION_UPDATE_PERIOD: process.env.SESSION_UPDATE_PERIOD,
|
2022-09-05 19:28:53 +02:00
|
|
|
ENCRYPTED_TEST_PUBLIC_API_KEY: process.env.ENCRYPTED_TEST_PUBLIC_API_KEY,
|
2024-01-25 17:22:39 +01:00
|
|
|
SESSION_EXPIRY_SECONDS: process.env.SESSION_EXPIRY_SECONDS,
|
2023-02-21 09:23:53 +01:00
|
|
|
/**
|
|
|
|
* Mock the email service in use - links to ethereal hosted emails are logged instead.
|
|
|
|
*/
|
|
|
|
ENABLE_EMAIL_TEST_MODE: process.env.ENABLE_EMAIL_TEST_MODE,
|
2023-03-06 16:26:09 +01:00
|
|
|
PASSPORT_GOOGLEAUTH_SUCCESS_REDIRECT:
|
|
|
|
process.env.PASSPORT_GOOGLEAUTH_SUCCESS_REDIRECT || "/",
|
|
|
|
PASSPORT_GOOGLEAUTH_FAILURE_REDIRECT:
|
|
|
|
process.env.PASSPORT_GOOGLEAUTH_FAILURE_REDIRECT || "/error",
|
|
|
|
PASSPORT_OIDCAUTH_SUCCESS_REDIRECT:
|
|
|
|
process.env.PASSPORT_OIDCAUTH_SUCCESS_REDIRECT || "/",
|
|
|
|
PASSPORT_OIDCAUTH_FAILURE_REDIRECT:
|
|
|
|
process.env.PASSPORT_OIDCAUTH_FAILURE_REDIRECT || "/error",
|
|
|
|
|
2022-08-25 20:41:47 +02:00
|
|
|
_set(key: any, value: any) {
|
2020-12-16 20:50:02 +01:00
|
|
|
process.env[key] = value
|
2022-11-25 13:52:50 +01:00
|
|
|
// @ts-ignore
|
2022-11-28 18:54:04 +01:00
|
|
|
environment[key] = value
|
2020-12-16 20:50:02 +01:00
|
|
|
},
|
2023-09-07 15:37:22 +02:00
|
|
|
isDev: coreEnv.isDev,
|
|
|
|
isTest: coreEnv.isTest,
|
2021-04-15 17:25:48 +02:00
|
|
|
isProd: () => {
|
2023-09-07 15:37:22 +02:00
|
|
|
return !coreEnv.isDev()
|
2021-04-15 17:25:48 +02:00
|
|
|
},
|
2020-12-16 20:50:02 +01:00
|
|
|
}
|
2021-10-11 18:59:44 +02:00
|
|
|
|
2021-11-04 15:53:03 +01:00
|
|
|
// if some var haven't been set, define them
|
2022-11-25 20:57:07 +01:00
|
|
|
if (!environment.APPS_URL) {
|
2023-09-07 15:37:22 +02:00
|
|
|
environment.APPS_URL = coreEnv.isDev()
|
2022-11-25 20:57:07 +01:00
|
|
|
? "http://localhost:4001"
|
|
|
|
: "http://app-service:4002"
|
2021-11-04 15:53:03 +01:00
|
|
|
}
|
|
|
|
|
2021-10-11 18:59:44 +02:00
|
|
|
// clean up any environment variable edge cases
|
2022-11-26 15:46:01 +01:00
|
|
|
for (let [key, value] of Object.entries(environment)) {
|
2021-10-11 18:59:44 +02:00
|
|
|
// handle the edge case of "0" to disable an environment variable
|
|
|
|
if (value === "0") {
|
2022-08-25 20:41:47 +02:00
|
|
|
// @ts-ignore
|
2022-11-29 23:11:44 +01:00
|
|
|
environment[key] = 0
|
2021-10-11 18:59:44 +02:00
|
|
|
}
|
2022-12-15 12:35:22 +01:00
|
|
|
// handle the edge case of "false" to disable an environment variable
|
|
|
|
if (value === "false") {
|
|
|
|
// @ts-ignore
|
|
|
|
environment[key] = 0
|
|
|
|
}
|
2021-10-11 18:59:44 +02:00
|
|
|
}
|
2022-08-25 20:41:47 +02:00
|
|
|
|
2023-01-11 10:37:37 +01:00
|
|
|
export default environment
|