From ff66ed35c6631349017a73208243e868f2f33fcc Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 12 Nov 2020 10:41:49 +0000 Subject: [PATCH] tidy up --- .../src/api/controllers/static/index.js | 32 +------------------ packages/server/src/api/routes/static.js | 2 +- packages/server/src/db/client.js | 2 +- .../builder/compileStaticAssetsForPage.js | 5 ++- .../src/utilities/initialiseBudibase.js | 4 +-- 5 files changed, 7 insertions(+), 38 deletions(-) diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index 19f51a06cb..462a65ad9b 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -141,16 +141,13 @@ exports.performLocalFileProcessing = async function(ctx) { } } -exports.serveAppNew = async function(ctx) { +exports.serveApp = async function(ctx) { const App = require("./templates/BudibaseApp.svelte").default - // Need to get app information here const db = new CouchDB(ctx.params.appId) const appInfo = await db.get(ctx.params.appId) - console.log("INFO", appInfo) - const { head, html, css } = App.render({ title: appInfo.name, pageName: @@ -170,33 +167,6 @@ exports.serveAppNew = async function(ctx) { }) } -exports.serveApp = async function(ctx) { - const mainOrAuth = - ctx.auth.authenticated === AuthTypes.APP ? "main" : "unauthenticated" - - // default to homedir - const appPath = resolve( - budibaseAppsDir(), - ctx.params.appId, - "public", - mainOrAuth - ) - - const appId = ctx.user.appId - - if (env.CLOUD) { - const S3_URL = `https://${appId}.app.budi.live/assets/${appId}/${mainOrAuth}/${ctx.file || - "index.production.html"}` - - const response = await fetch(S3_URL) - const body = await response.text() - ctx.body = body - return - } - - await send(ctx, ctx.file || "index.html", { root: ctx.devPath || appPath }) -} - exports.serveAttachment = async function(ctx) { const appId = ctx.user.appId const attachmentsPath = resolve(budibaseAppsDir(), appId, "attachments") diff --git a/packages/server/src/api/routes/static.js b/packages/server/src/api/routes/static.js index e832df17c4..5c33900eca 100644 --- a/packages/server/src/api/routes/static.js +++ b/packages/server/src/api/routes/static.js @@ -33,6 +33,6 @@ router .get("/componentlibrary", controller.serveComponentLibrary) .get("/assets/:file*", controller.serveAppAsset) .get("/attachments/:file*", controller.serveAttachment) - .get("/:appId/:path*", controller.serveAppNew) + .get("/:appId/:path*", controller.serveApp) module.exports = router diff --git a/packages/server/src/db/client.js b/packages/server/src/db/client.js index 1d025a1402..1477ee4315 100644 --- a/packages/server/src/db/client.js +++ b/packages/server/src/db/client.js @@ -38,6 +38,6 @@ function replicateLocal() { }) } -replicateLocal() +// replicateLocal() module.exports = Pouch diff --git a/packages/server/src/utilities/builder/compileStaticAssetsForPage.js b/packages/server/src/utilities/builder/compileStaticAssetsForPage.js index 9e2dc23ede..c91ba24bb3 100644 --- a/packages/server/src/utilities/builder/compileStaticAssetsForPage.js +++ b/packages/server/src/utilities/builder/compileStaticAssetsForPage.js @@ -1,6 +1,5 @@ const { ensureDir, constants, copyFile, writeFile } = require("fs-extra") const { join } = require("../centralPath") -const { convertCssToBundle } = require("./convertCssToFiles") const { budibaseAppsDir } = require("../budibaseDir") /** @@ -19,7 +18,7 @@ module.exports = async (appId, pageName, pkg) => { await ensureDir(pagePath) - await convertCssToBundle(pagePath, pkg) + await buildPageCssBundle(pagePath, pkg) await buildFrontendAppDefinition(pagePath, pkg) @@ -33,7 +32,7 @@ module.exports = async (appId, pageName, pkg) => { * @param {Object} pkg - app package information * @param {"main" | "unauthenticated"} pageName - the pagename of the page we are compiling CSS for. */ -module.exports.convertCssToBundle = async (publicPagePath, pkg) => { +const buildPageCssBundle = async (publicPagePath, pkg) => { let cssString = "" for (let screen of pkg.screens || []) { diff --git a/packages/server/src/utilities/initialiseBudibase.js b/packages/server/src/utilities/initialiseBudibase.js index 1a88b4d1c2..4073c2be69 100644 --- a/packages/server/src/utilities/initialiseBudibase.js +++ b/packages/server/src/utilities/initialiseBudibase.js @@ -31,8 +31,8 @@ const createDevEnvFile = async opts => { } ) opts.cookieKey1 = opts.cookieKey1 || uuid.v4() - const hbTemplate = handlebars.compile(template) - const config = hbTemplate.render(opts) + const envTemplate = handlebars.compile(template) + const config = envTemplate(opts) await writeFile(destConfigFile, config, { flag: "w+" }) } }