1
0
Fork 0
mirror of synced 2024-10-02 18:16:29 +13:00

utility helper for determining correct couchDB URL

This commit is contained in:
Martin McKeaveney 2021-08-16 16:38:00 +01:00
parent 769c37a11d
commit beb16a733e
3 changed files with 17 additions and 9 deletions

View file

@ -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

View file

@ -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,

View file

@ -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)
}