Some refactoring of utilities and constants, as well as documenting work carried out here.
This commit is contained in:
parent
de694ff338
commit
95efc26839
|
@ -24,8 +24,10 @@ router.param("file", async (file, ctx, next) => {
|
||||||
return next()
|
return next()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// only used in development for retrieving the client library,
|
||||||
|
// in production the client lib is always stored in the object store.
|
||||||
if (env.isDev()) {
|
if (env.isDev()) {
|
||||||
router.get("/assets/client", controller.serveClientLibrary)
|
router.get("/api/assets/client", controller.serveClientLibrary)
|
||||||
}
|
}
|
||||||
|
|
||||||
router
|
router
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
const { BUILTIN_ROLE_IDS } = require("../utilities/security/roles")
|
const { BUILTIN_ROLE_IDS } = require("../utilities/security/roles")
|
||||||
|
|
||||||
|
exports.LOGO_URL =
|
||||||
|
"https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg"
|
||||||
|
|
||||||
exports.FieldTypes = {
|
exports.FieldTypes = {
|
||||||
STRING: "string",
|
STRING: "string",
|
||||||
LONGFORM: "longform",
|
LONGFORM: "longform",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const { getLogoUrl } = require("../utilities")
|
const { LOGO_URL } = require("../constants")
|
||||||
|
|
||||||
const BASE_LAYOUT_PROP_IDS = {
|
const BASE_LAYOUT_PROP_IDS = {
|
||||||
PRIVATE: "layout_private_master",
|
PRIVATE: "layout_private_master",
|
||||||
|
@ -109,7 +109,7 @@ const BASE_LAYOUTS = [
|
||||||
active: {},
|
active: {},
|
||||||
selected: {},
|
selected: {},
|
||||||
},
|
},
|
||||||
logoUrl: getLogoUrl(),
|
logoUrl: LOGO_URL,
|
||||||
title: "",
|
title: "",
|
||||||
backgroundColor: "",
|
backgroundColor: "",
|
||||||
color: "",
|
color: "",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const { BUILTIN_ROLE_IDS } = require("../utilities/security/roles")
|
const { BUILTIN_ROLE_IDS } = require("../utilities/security/roles")
|
||||||
const { BASE_LAYOUT_PROP_IDS } = require("./layouts")
|
const { BASE_LAYOUT_PROP_IDS } = require("./layouts")
|
||||||
const { getLogoUrl } = require("../utilities")
|
const { LOGO_URL } = require("../constants")
|
||||||
|
|
||||||
exports.createHomeScreen = () => ({
|
exports.createHomeScreen = () => ({
|
||||||
description: "",
|
description: "",
|
||||||
|
@ -92,7 +92,7 @@ exports.createLoginScreen = app => ({
|
||||||
active: {},
|
active: {},
|
||||||
selected: {},
|
selected: {},
|
||||||
},
|
},
|
||||||
logo: getLogoUrl(),
|
logo: LOGO_URL,
|
||||||
title: `Log in to ${app.name}`,
|
title: `Log in to ${app.name}`,
|
||||||
buttonText: "Log In",
|
buttonText: "Log In",
|
||||||
_children: [],
|
_children: [],
|
||||||
|
|
|
@ -87,14 +87,23 @@ exports.clearCookie = (ctx, name) => {
|
||||||
exports.setCookie(ctx, "", name)
|
exports.setCookie(ctx, "", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the API call being made (based on the provided ctx object) is from the client. If
|
||||||
|
* the call is not from a client app then it is from the builder.
|
||||||
|
* @param {object} ctx The koa context object to be tested.
|
||||||
|
* @return {boolean} returns true if the call is from the client lib (a built app rather than the builder).
|
||||||
|
*/
|
||||||
exports.isClient = ctx => {
|
exports.isClient = ctx => {
|
||||||
return ctx.headers["x-budibase-type"] === "client"
|
return ctx.headers["x-budibase-type"] === "client"
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getLogoUrl = () => {
|
/**
|
||||||
return "https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg"
|
* Lots of different points in the app need to find the full list of apps, this will
|
||||||
}
|
* enumerate the entire CouchDB cluster and get the list of databases (every app).
|
||||||
|
* NOTE: this operation is fine in self hosting, but cannot be used when hosting many
|
||||||
|
* different users/companies apps as there is no security around it - all apps are returned.
|
||||||
|
* @return {Promise<object[]>} returns the app information document stored in each app database.
|
||||||
|
*/
|
||||||
exports.getAllApps = async () => {
|
exports.getAllApps = async () => {
|
||||||
let allDbs = await CouchDB.allDbs()
|
let allDbs = await CouchDB.allDbs()
|
||||||
const appDbNames = allDbs.filter(dbName => dbName.startsWith(APP_PREFIX))
|
const appDbNames = allDbs.filter(dbName => dbName.startsWith(APP_PREFIX))
|
||||||
|
@ -109,10 +118,20 @@ exports.getAllApps = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes sure that a URL has the correct number of slashes, while maintaining the
|
||||||
|
* http(s):// double slashes.
|
||||||
|
* @param {string} url The URL to test and remove any extra double slashes.
|
||||||
|
* @return {string} The updated url.
|
||||||
|
*/
|
||||||
exports.checkSlashesInUrl = url => {
|
exports.checkSlashesInUrl = url => {
|
||||||
return url.replace(/(https?:\/\/)|(\/)+/g, "$1$2")
|
return url.replace(/(https?:\/\/)|(\/)+/g, "$1$2")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the address of the object store, depending on whether self hosted or in cloud.
|
||||||
|
* @return {string} The base URL of the object store (MinIO or S3).
|
||||||
|
*/
|
||||||
exports.objectStoreUrl = () => {
|
exports.objectStoreUrl = () => {
|
||||||
if (env.SELF_HOSTED) {
|
if (env.SELF_HOSTED) {
|
||||||
// can use a relative url for this as all goes through the proxy (this is hosted in minio)
|
// can use a relative url for this as all goes through the proxy (this is hosted in minio)
|
||||||
|
@ -122,10 +141,19 @@ exports.objectStoreUrl = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In production the client library is stored in the object store, however in development
|
||||||
|
* we use the symlinked version produced by lerna, located in node modules. We link to this
|
||||||
|
* via a specific endpoint (under /api/assets/client).
|
||||||
|
* @param {string} appId In production we need the appId to look up the correct bucket, as the
|
||||||
|
* version of the client lib may differ between apps.
|
||||||
|
* @return {string} The URL to be inserted into appPackage response or server rendered
|
||||||
|
* app index file.
|
||||||
|
*/
|
||||||
exports.clientLibraryPath = appId => {
|
exports.clientLibraryPath = appId => {
|
||||||
if (env.isProd()) {
|
if (env.isProd()) {
|
||||||
return `${exports.objectStoreUrl()}/${appId}/budibase-client.js`
|
return `${exports.objectStoreUrl()}/${appId}/budibase-client.js`
|
||||||
} else {
|
} else {
|
||||||
return `/assets/client`
|
return `/api/assets/client`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue