From 8ea12c30a6cd861563b2f9c223a3b5a9d9ef0c05 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 1 Apr 2021 12:48:38 +0100 Subject: [PATCH] Updating how the client library is served in development. --- .../server/src/api/controllers/application.js | 2 ++ .../src/api/controllers/static/index.js | 32 ++++++------------- .../static/templates/BudibaseApp.svelte | 12 ++----- packages/server/src/api/routes/static.js | 4 +++ packages/server/src/utilities/index.js | 19 +++++++++++ 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index 00678b85a0..cacde4bb00 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -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) } diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index 8aaa19cc63..ec3db6bbd3 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -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 diff --git a/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte b/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte index a83ebc781a..ee819ed8b5 100644 --- a/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte +++ b/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte @@ -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 @@ -44,7 +36,7 @@ -