Merge pull request #2405 from Budibase/simplify-couch-config

simplify couchDB configuration
This commit is contained in:
Martin McKeaveney 2021-08-18 13:01:48 +01:00 committed by GitHub
commit d50dad61c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 19 deletions

View File

@ -159,6 +159,8 @@ exports.getDeployedAppID = appId => {
} }
exports.getCouchUrl = () => { exports.getCouchUrl = () => {
if (!env.COUCH_DB_URL) return
// username and password already exist in URL // username and password already exist in URL
if (env.COUCH_DB_URL.includes("@")) { if (env.COUCH_DB_URL.includes("@")) {
return env.COUCH_DB_URL return env.COUCH_DB_URL
@ -166,6 +168,12 @@ exports.getCouchUrl = () => {
const [protocol, ...rest] = env.COUCH_DB_URL.split("://") const [protocol, ...rest] = env.COUCH_DB_URL.split("://")
if (!env.COUCH_DB_USERNAME || !env.COUCH_DB_PASSWORD) {
throw new Error(
"CouchDB configuration invalid. You must provide a fully qualified CouchDB url, or the COUCH_DB_USER and COUCH_DB_PASSWORD environment variables."
)
}
return `${protocol}://${env.COUCH_DB_USERNAME}:${env.COUCH_DB_PASSWORD}@${rest}` return `${protocol}://${env.COUCH_DB_USERNAME}:${env.COUCH_DB_PASSWORD}@${rest}`
} }

View File

@ -9,7 +9,7 @@ function isTest() {
module.exports = { module.exports = {
JWT_SECRET: process.env.JWT_SECRET, JWT_SECRET: process.env.JWT_SECRET,
COUCH_DB_URL: process.env.COUCH_DB_URL, COUCH_DB_URL: process.env.COUCH_DB_URL,
COUCH_DB_USERNAME: process.env.COUCH_DB_USER || process.env.COUCH_DB_USERNAME, COUCH_DB_USERNAME: process.env.COUCH_DB_USER,
COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD, COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD,
SALT_ROUNDS: process.env.SALT_ROUNDS, SALT_ROUNDS: process.env.SALT_ROUNDS,
REDIS_URL: process.env.REDIS_URL, REDIS_URL: process.env.REDIS_URL,

View File

@ -1,10 +1,11 @@
const PouchDB = require("pouchdb") const PouchDB = require("pouchdb")
const { getCouchUrl } = require("@budibase/auth/db")
const replicationStream = require("pouchdb-replication-stream") const replicationStream = require("pouchdb-replication-stream")
const allDbs = require("pouchdb-all-dbs") const allDbs = require("pouchdb-all-dbs")
const find = require("pouchdb-find") const find = require("pouchdb-find")
const env = require("../environment") const env = require("../environment")
const COUCH_DB_URL = env.COUCH_DB_URL || "http://localhost:10000/db/" const COUCH_DB_URL = getCouchUrl() || "http://localhost:10000/db/"
PouchDB.plugin(replicationStream.plugin) PouchDB.plugin(replicationStream.plugin)
PouchDB.plugin(find) PouchDB.plugin(find)
@ -14,13 +15,6 @@ let POUCH_DB_DEFAULTS = {
prefix: COUCH_DB_URL, prefix: COUCH_DB_URL,
} }
if (env.COUCH_DB_USERNAME && env.COUCH_DB_PASSWORD) {
POUCH_DB_DEFAULTS.auth = {
username: env.COUCH_DB_USERNAME,
password: env.COUCH_DB_PASSWORD,
}
}
if (env.isTest()) { if (env.isTest()) {
PouchDB.plugin(require("pouchdb-adapter-memory")) PouchDB.plugin(require("pouchdb-adapter-memory"))
POUCH_DB_DEFAULTS = { POUCH_DB_DEFAULTS = {

View File

@ -24,8 +24,6 @@ module.exports = {
PORT: process.env.PORT, PORT: process.env.PORT,
JWT_SECRET: process.env.JWT_SECRET, JWT_SECRET: process.env.JWT_SECRET,
COUCH_DB_URL: process.env.COUCH_DB_URL, COUCH_DB_URL: process.env.COUCH_DB_URL,
COUCH_DB_USERNAME: process.env.COUCH_DB_USER,
COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD,
MINIO_URL: process.env.MINIO_URL, MINIO_URL: process.env.MINIO_URL,
WORKER_URL: process.env.WORKER_URL, WORKER_URL: process.env.WORKER_URL,
SELF_HOSTED: process.env.SELF_HOSTED, SELF_HOSTED: process.env.SELF_HOSTED,

View File

@ -1,21 +1,15 @@
const PouchDB = require("pouchdb") const PouchDB = require("pouchdb")
const allDbs = require("pouchdb-all-dbs") const allDbs = require("pouchdb-all-dbs")
const env = require("../environment") const env = require("../environment")
const { getCouchUrl } = require("@budibase/auth/db")
// level option is purely for testing (development) // level option is purely for testing (development)
const COUCH_DB_URL = env.COUCH_DB_URL || "http://localhost:10000/db/" const COUCH_DB_URL = getCouchUrl() || "http://localhost:10000/db/"
let POUCH_DB_DEFAULTS = { let POUCH_DB_DEFAULTS = {
prefix: COUCH_DB_URL, prefix: COUCH_DB_URL,
} }
if (env.COUCH_DB_USERNAME && env.COUCH_DB_PASSWORD) {
POUCH_DB_DEFAULTS.auth = {
username: env.COUCH_DB_USERNAME,
password: env.COUCH_DB_PASSWORD,
}
}
if (env.isTest()) { if (env.isTest()) {
PouchDB.plugin(require("pouchdb-adapter-memory")) PouchDB.plugin(require("pouchdb-adapter-memory"))
POUCH_DB_DEFAULTS = { POUCH_DB_DEFAULTS = {