1
0
Fork 0
mirror of synced 2024-06-21 11:51:00 +12:00

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

View file

@ -2,7 +2,6 @@ require("svelte/register")
const send = require("koa-send")
const { resolve, join } = require("../../../utilities/centralPath")
const { checkSlashesInUrl } = require("../../../utilities")
const fetch = require("node-fetch")
const uuid = require("uuid")
const { prepareUpload } = require("../deploy/utils")
@ -13,27 +12,10 @@ const CouchDB = require("../../../db")
const setBuilderToken = require("../../../utilities/builder/setBuilderToken")
const { loadHandlebarsFile } = require("../../../utilities/fileSystem")
const env = require("../../../environment")
const { OBJ_STORE_DIRECTORY } = require("../../../constants")
const fileProcessor = require("../../../utilities/fileSystem/processor")
const { objectStoreUrl, clientLibraryPath } = require("../../../utilities")
const BB_CDN = "https://cdn.app.budi.live/assets"
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
}
}
const TOP_LEVEL = join(__dirname, "..", "..", "..", "..")
async function checkForSelfHostedURL(ctx) {
// 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"
exports.serveBuilder = async function(ctx) {
let builderPath = resolve(__dirname, "../../../../builder")
let builderPath = resolve(TOP_LEVEL, "builder")
if (ctx.file === "index.html") {
await setBuilderToken(ctx)
}
@ -97,7 +79,7 @@ exports.serveApp = async function(ctx) {
title: appInfo.name,
production: env.isProd(),
appId,
objectStoreUrl: objectStoreUrl(),
clientLibPath: clientLibraryPath(appId),
})
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) {
const appId = ctx.query.appId || ctx.appId

View file

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

View file

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

View file

@ -1,7 +1,9 @@
const env = require("../environment")
const { DocumentTypes, SEPARATOR } = require("../db/utils")
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
function confirmAppId(possibleAppId) {
@ -110,3 +112,20 @@ exports.getAllApps = async () => {
exports.checkSlashesInUrl = url => {
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`
}
}