Updating how the client library is served in development.

This commit is contained in:
mike12345567 2021-04-01 12:48:38 +01:00
parent d2bdb439ef
commit 8ea12c30a6
5 changed files with 37 additions and 32 deletions

View File

@ -32,6 +32,7 @@ const { processObject } = require("@budibase/string-templates")
const { getAllApps } = require("../../utilities") const { getAllApps } = require("../../utilities")
const { USERS_TABLE_SCHEMA } = require("../../constants") const { USERS_TABLE_SCHEMA } = require("../../constants")
const { getDeployedApps } = require("../../utilities/builder/hosting") const { getDeployedApps } = require("../../utilities/builder/hosting")
const { clientLibraryPath } = require("../../utilities")
const URL_REGEX_SLASH = /\/|\\/g const URL_REGEX_SLASH = /\/|\\/g
@ -142,6 +143,7 @@ exports.fetchAppPackage = async function(ctx) {
application, application,
screens, screens,
layouts, layouts,
clientLibPath: clientLibraryPath(ctx.params.appId),
} }
await setBuilderToken(ctx, ctx.params.appId, application.version) await setBuilderToken(ctx, ctx.params.appId, application.version)
} }

View File

@ -2,7 +2,6 @@ require("svelte/register")
const send = require("koa-send") const send = require("koa-send")
const { resolve, join } = require("../../../utilities/centralPath") const { resolve, join } = require("../../../utilities/centralPath")
const { checkSlashesInUrl } = require("../../../utilities")
const fetch = require("node-fetch") const fetch = require("node-fetch")
const uuid = require("uuid") const uuid = require("uuid")
const { prepareUpload } = require("../deploy/utils") const { prepareUpload } = require("../deploy/utils")
@ -13,27 +12,10 @@ const CouchDB = require("../../../db")
const setBuilderToken = require("../../../utilities/builder/setBuilderToken") const setBuilderToken = require("../../../utilities/builder/setBuilderToken")
const { loadHandlebarsFile } = require("../../../utilities/fileSystem") const { loadHandlebarsFile } = require("../../../utilities/fileSystem")
const env = require("../../../environment") const env = require("../../../environment")
const { OBJ_STORE_DIRECTORY } = require("../../../constants")
const fileProcessor = require("../../../utilities/fileSystem/processor") const fileProcessor = require("../../../utilities/fileSystem/processor")
const { objectStoreUrl, clientLibraryPath } = require("../../../utilities")
const BB_CDN = "https://cdn.app.budi.live/assets" const TOP_LEVEL = join(__dirname, "..", "..", "..", "..")
function objectStoreUrl() {
if (env.SELF_HOSTED) {
// can use a relative url for this as all goes through the proxy (this is hosted in minio)
return OBJ_STORE_DIRECTORY
} else {
return BB_CDN
}
}
function internalObjectStoreUrl() {
if (env.SELF_HOSTED) {
return checkSlashesInUrl(env.MINIO_URL + OBJ_STORE_DIRECTORY)
} else {
return BB_CDN
}
}
async function checkForSelfHostedURL(ctx) { async function checkForSelfHostedURL(ctx) {
// the "appId" component of the URL may actually be a specific self hosted URL // the "appId" component of the URL may actually be a specific self hosted URL
@ -50,7 +32,7 @@ async function checkForSelfHostedURL(ctx) {
const COMP_LIB_BASE_APP_VERSION = "0.2.5" const COMP_LIB_BASE_APP_VERSION = "0.2.5"
exports.serveBuilder = async function(ctx) { exports.serveBuilder = async function(ctx) {
let builderPath = resolve(__dirname, "../../../../builder") let builderPath = resolve(TOP_LEVEL, "builder")
if (ctx.file === "index.html") { if (ctx.file === "index.html") {
await setBuilderToken(ctx) await setBuilderToken(ctx)
} }
@ -97,7 +79,7 @@ exports.serveApp = async function(ctx) {
title: appInfo.name, title: appInfo.name,
production: env.isProd(), production: env.isProd(),
appId, appId,
objectStoreUrl: objectStoreUrl(), clientLibPath: clientLibraryPath(appId),
}) })
const appHbs = loadHandlebarsFile(`${__dirname}/templates/app.hbs`) const appHbs = loadHandlebarsFile(`${__dirname}/templates/app.hbs`)
@ -109,6 +91,12 @@ exports.serveApp = async function(ctx) {
}) })
} }
exports.serveClientLibrary = async function(ctx) {
return send(ctx, "budibase-client.js", {
root: join(TOP_LEVEL, "node_modules", "@budibase", "client", "dist"),
})
}
exports.serveComponentLibrary = async function(ctx) { exports.serveComponentLibrary = async function(ctx) {
const appId = ctx.query.appId || ctx.appId const appId = ctx.query.appId || ctx.appId

View File

@ -4,15 +4,7 @@
export let appId export let appId
export let production export let production
export let objectStoreUrl export let clientLibPath
function publicPath(path) {
if (production) {
return `${objectStoreUrl}/${appId}/${path}`
} else {
return `/builder/assets/${path}`
}
}
</script> </script>
<svelte:head> <svelte:head>
@ -44,7 +36,7 @@
</svelte:head> </svelte:head>
<body id="app"> <body id="app">
<script src={publicPath('budibase-client.js')}> <script src={clientLibPath}>
</script> </script>
<script> <script>
loadBudibase() loadBudibase()

View File

@ -24,6 +24,10 @@ router.param("file", async (file, ctx, next) => {
return next() return next()
}) })
if (env.isDev()) {
router.get("/assets/client", controller.serveClientLibrary)
}
router router
// TODO: for now this builder endpoint is not authorized/secured, will need to be // TODO: for now this builder endpoint is not authorized/secured, will need to be
.get("/builder/:file*", controller.serveBuilder) .get("/builder/:file*", controller.serveBuilder)

View File

@ -1,7 +1,9 @@
const env = require("../environment") const env = require("../environment")
const { DocumentTypes, SEPARATOR } = require("../db/utils") const { DocumentTypes, SEPARATOR } = require("../db/utils")
const CouchDB = require("../db") const CouchDB = require("../db")
const { OBJ_STORE_DIRECTORY } = require("../constants")
const BB_CDN = "https://cdn.app.budi.live/assets"
const APP_PREFIX = DocumentTypes.APP + SEPARATOR const APP_PREFIX = DocumentTypes.APP + SEPARATOR
function confirmAppId(possibleAppId) { function confirmAppId(possibleAppId) {
@ -110,3 +112,20 @@ exports.getAllApps = async () => {
exports.checkSlashesInUrl = url => { exports.checkSlashesInUrl = url => {
return url.replace(/(https?:\/\/)|(\/)+/g, "$1$2") return url.replace(/(https?:\/\/)|(\/)+/g, "$1$2")
} }
exports.objectStoreUrl = () => {
if (env.SELF_HOSTED) {
// can use a relative url for this as all goes through the proxy (this is hosted in minio)
return OBJ_STORE_DIRECTORY
} else {
return BB_CDN
}
}
exports.clientLibraryPath = appId => {
if (env.isProd()) {
return `${exports.objectStoreUrl()}/${appId}/budibase-client.js`
} else {
return `/assets/client`
}
}