utility helper for determining correct couchDB URL
This commit is contained in:
parent
8718488aee
commit
884b36730b
|
@ -159,6 +159,17 @@ exports.getDeployedAppID = appId => {
|
|||
return appId
|
||||
}
|
||||
|
||||
exports.getCouchUrl = () => {
|
||||
// username and password already exist in URL
|
||||
if (env.COUCH_DB_URL.includes("@")) {
|
||||
return env.COUCH_DB_URL
|
||||
}
|
||||
|
||||
const [protocol, ...rest] = env.COUCH_DB_URL.split("://")
|
||||
|
||||
return `${protocol}://${env.COUCH_DB_USERNAME}:${env.COUCH_DB_PASSWORD}@${rest}`
|
||||
}
|
||||
|
||||
/**
|
||||
* if in production this will use the CouchDB _all_dbs call to retrieve a list of databases. If testing
|
||||
* when using Pouch it will use the pouchdb-all-dbs package.
|
||||
|
@ -168,13 +179,7 @@ exports.getAllDbs = async () => {
|
|||
if (env.isTest()) {
|
||||
return getCouch().allDbs()
|
||||
}
|
||||
const response = await fetch(`${env.COUCH_DB_URL}/_all_dbs`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
name: env.COUCH_DB_USERNAME,
|
||||
password: env.COUCH_DB_PASSWORD,
|
||||
}),
|
||||
})
|
||||
const response = await fetch(`${exports.getCouchUrl()}/_all_dbs`)
|
||||
if (response.status === 200) {
|
||||
return response.json()
|
||||
} else {
|
||||
|
@ -309,4 +314,4 @@ exports.Replication = Replication
|
|||
exports.getScopedConfig = getScopedConfig
|
||||
exports.generateConfigID = generateConfigID
|
||||
exports.getConfigParams = getConfigParams
|
||||
exports.getScopedFullConfig = getScopedFullConfig
|
||||
exports.getScopedFullConfig = getScopedFullConfig
|
|
@ -9,6 +9,8 @@ function isTest() {
|
|||
module.exports = {
|
||||
JWT_SECRET: process.env.JWT_SECRET,
|
||||
COUCH_DB_URL: process.env.COUCH_DB_URL,
|
||||
COUCH_DB_USERNAME: process.env.COUCH_DB_USER,
|
||||
COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD,
|
||||
SALT_ROUNDS: process.env.SALT_ROUNDS,
|
||||
REDIS_URL: process.env.REDIS_URL,
|
||||
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const { SearchIndexes } = require("../../../db/utils")
|
||||
const env = require("../../../environment")
|
||||
const fetch = require("node-fetch")
|
||||
const { getCouchUrl } = require("@budibase/auth/db")
|
||||
|
||||
/**
|
||||
* Class to build lucene query URLs.
|
||||
|
@ -233,7 +234,7 @@ class QueryBuilder {
|
|||
}
|
||||
|
||||
async run() {
|
||||
const url = `${env.COUCH_DB_URL}/${this.appId}/_design/database/_search/${SearchIndexes.ROWS}`
|
||||
const url = `${getCouchUrl()}/${this.appId}/_design/database/_search/${SearchIndexes.ROWS}`
|
||||
const body = this.buildSearchBody()
|
||||
return await runQuery(url, body)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue