budibase/packages/worker/src/utilities/templates.js

35 lines
1.3 KiB
JavaScript
Raw Normal View History

const CouchDB = require("../db")
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
}
// TODO: need to fully spec out the context
2021-04-23 19:54:12 +02:00
const URL = settings.platformUrl
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`),
[TemplateBindings.COMPANY]: settings.company || BASE_COMPANY,
[TemplateBindings.DOCS_URL]: settings.docsUrl || "https://docs.budibase.com/",
[TemplateBindings.LOGIN_URL]: checkSlashesInUrl(`${URL}/login`),
}
2021-04-22 18:58:14 +02:00
}