2021-04-23 19:07:39 +02:00
|
|
|
const CouchDB = require("../db")
|
2021-04-22 18:57:38 +02:00
|
|
|
const { getConfigParams, StaticDatabases } = require("@budibase/auth").db
|
|
|
|
const { Configs, TemplateBindings, LOGO_URL } = require("../constants")
|
|
|
|
const { checkSlashesInUrl } = require("./index")
|
|
|
|
const env = require("../environment")
|
|
|
|
|
|
|
|
const LOCAL_URL = `http://localhost:${env.PORT}`
|
|
|
|
const BASE_COMPANY = "Budibase"
|
|
|
|
|
|
|
|
exports.getSettingsTemplateContext = async () => {
|
|
|
|
const db = new CouchDB(StaticDatabases.GLOBAL.name)
|
|
|
|
const response = await db.allDocs(
|
|
|
|
getConfigParams(Configs.SETTINGS, {
|
|
|
|
include_docs: true,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
let settings = response.rows.map(row => row.doc)[0] || {}
|
2021-04-23 19:54:12 +02:00
|
|
|
if (!settings.platformUrl) {
|
|
|
|
settings.platformUrl = LOCAL_URL
|
2021-04-22 18:57:38 +02:00
|
|
|
}
|
|
|
|
// TODO: need to fully spec out the context
|
2021-04-23 19:54:12 +02:00
|
|
|
const URL = settings.platformUrl
|
2021-04-22 18:57:38 +02:00
|
|
|
return {
|
|
|
|
[TemplateBindings.LOGO_URL]: settings.logoUrl || LOGO_URL,
|
2021-04-23 19:54:12 +02:00
|
|
|
[TemplateBindings.PLATFORM_URL]: URL,
|
2021-04-22 18:58:14 +02:00
|
|
|
[TemplateBindings.REGISTRATION_URL]: checkSlashesInUrl(
|
2021-04-23 19:54:12 +02:00
|
|
|
`${URL}/registration`
|
2021-04-22 18:58:14 +02:00
|
|
|
),
|
2021-04-23 19:54:12 +02:00
|
|
|
[TemplateBindings.RESET_URL]: checkSlashesInUrl(`${URL}/reset`),
|
2021-04-22 18:57:38 +02:00
|
|
|
[TemplateBindings.COMPANY]: settings.company || BASE_COMPANY,
|
2021-04-26 15:16:05 +02:00
|
|
|
[TemplateBindings.DOCS_URL]:
|
|
|
|
settings.docsUrl || "https://docs.budibase.com/",
|
2021-04-26 15:14:51 +02:00
|
|
|
[TemplateBindings.LOGIN_URL]: checkSlashesInUrl(`${URL}/login`),
|
2021-04-22 18:57:38 +02:00
|
|
|
}
|
2021-04-22 18:58:14 +02:00
|
|
|
}
|