From 73881e9895731a98258c30fefb3dbd3cd658294a Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 11 Jul 2024 11:11:28 +0100 Subject: [PATCH] Only default the CouchDB SQL URL if we are in dev, otherwise attempt to work out what it is based on the main CouchDB URL (as this should work in all default production environments). --- packages/backend-core/src/db/couch/connections.ts | 5 ++++- packages/backend-core/src/environment.ts | 2 +- packages/server/src/environment.ts | 3 +-- .../worker/src/api/controllers/system/environment.ts | 9 +++++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/backend-core/src/db/couch/connections.ts b/packages/backend-core/src/db/couch/connections.ts index 454715e2cb..5c7d7ec81d 100644 --- a/packages/backend-core/src/db/couch/connections.ts +++ b/packages/backend-core/src/db/couch/connections.ts @@ -25,7 +25,10 @@ export const getCouchInfo = (connection?: string) => { } const authCookie = Buffer.from(`${username}:${password}`).toString("base64") let sqlUrl = env.COUCH_DB_SQL_URL - if (!sqlUrl && urlInfo.url) { + // default for dev + if (env.isDev() && !sqlUrl) { + sqlUrl = "http://localhost:4006" + } else if (!sqlUrl && urlInfo.url) { const parsed = new URL(urlInfo.url) // attempt to connect on default port sqlUrl = urlInfo.url.replace(parsed.port, "4984") diff --git a/packages/backend-core/src/environment.ts b/packages/backend-core/src/environment.ts index 8ed96b32c3..64e3187956 100644 --- a/packages/backend-core/src/environment.ts +++ b/packages/backend-core/src/environment.ts @@ -114,7 +114,7 @@ const environment = { ENCRYPTION_KEY: process.env.ENCRYPTION_KEY, API_ENCRYPTION_KEY: getAPIEncryptionKey(), COUCH_DB_URL: process.env.COUCH_DB_URL || "http://localhost:4005", - COUCH_DB_SQL_URL: process.env.COUCH_DB_SQL_URL || "http://localhost:4006", + COUCH_DB_SQL_URL: process.env.COUCH_DB_SQL_URL, SQS_SEARCH_ENABLE: process.env.SQS_SEARCH_ENABLE, SQS_SEARCH_ENABLE_TENANTS: process.env.SQS_SEARCH_ENABLE_TENANTS?.split(",") || [], diff --git a/packages/server/src/environment.ts b/packages/server/src/environment.ts index 28673dcaa8..e1525ebd1b 100644 --- a/packages/server/src/environment.ts +++ b/packages/server/src/environment.ts @@ -28,7 +28,6 @@ const DEFAULTS = { PLUGINS_DIR: "/plugins", FORKED_PROCESS_NAME: "main", JS_RUNNER_MEMORY_LIMIT: 64, - COUCH_DB_SQL_URL: "http://localhost:4006", } const QUERY_THREAD_TIMEOUT = @@ -44,7 +43,7 @@ const environment = { // important - prefer app port to generic port PORT: process.env.APP_PORT || process.env.PORT, COUCH_DB_URL: process.env.COUCH_DB_URL, - COUCH_DB_SQL_URL: process.env.COUCH_DB_SQL_URL || DEFAULTS.COUCH_DB_SQL_URL, + COUCH_DB_SQL_URL: process.env.COUCH_DB_SQL_URL, MINIO_URL: process.env.MINIO_URL, WORKER_URL: process.env.WORKER_URL, AWS_REGION: process.env.AWS_REGION, diff --git a/packages/worker/src/api/controllers/system/environment.ts b/packages/worker/src/api/controllers/system/environment.ts index 788b45f25d..59a4e095dc 100644 --- a/packages/worker/src/api/controllers/system/environment.ts +++ b/packages/worker/src/api/controllers/system/environment.ts @@ -1,6 +1,6 @@ import { Ctx, MaintenanceType } from "@budibase/types" import env from "../../../environment" -import { env as coreEnv } from "@budibase/backend-core" +import { env as coreEnv, db as dbCore } from "@budibase/backend-core" import nodeFetch from "node-fetch" let sqsAvailable: boolean @@ -12,7 +12,12 @@ async function isSqsAvailable() { } try { - await nodeFetch(coreEnv.COUCH_DB_SQL_URL, { + const couchInfo = dbCore.getCouchInfo() + if (!couchInfo.sqlUrl) { + sqsAvailable = false + return false + } + await nodeFetch(couchInfo.sqlUrl, { timeout: 1000, }) sqsAvailable = true