Skip to content

Commit

Permalink
Merge pull request #14137 from Budibase/fix/sql-url-dev-only-default
Browse files Browse the repository at this point in the history
Fix for default CouchDB SQL URL
  • Loading branch information
mike12345567 authored Jul 11, 2024
2 parents d94d7b4 + 73881e9 commit bd2bbe4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion packages/backend-core/src/db/couch/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-core/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(",") || [],
Expand Down
3 changes: 1 addition & 2 deletions packages/server/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions packages/worker/src/api/controllers/system/environment.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit bd2bbe4

Please sign in to comment.