From e235de54adfbe80ac136ef4af75d4417878dbe78 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 30 Oct 2024 17:32:39 +0000 Subject: [PATCH 1/2] Fixing an issue with serving the builder, increased error rate due to requests that hit the / endpoint, these were 500ing due to a lack of app ID. --- .../server/src/api/controllers/static/index.ts | 11 +++++++++++ .../server/src/api/routes/tests/static.spec.ts | 18 ++++++++++++++++++ .../src/sdk/app/applications/applications.ts | 8 +++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/static/index.ts b/packages/server/src/api/controllers/static/index.ts index 1d04811019..b90d24c9b1 100644 --- a/packages/server/src/api/controllers/static/index.ts +++ b/packages/server/src/api/controllers/static/index.ts @@ -6,6 +6,7 @@ import { ObjectStoreBuckets } from "../../../constants" import { processString } from "@budibase/string-templates" import { loadHandlebarsFile, + streamFile, NODE_MODULES_PATH, shouldServeLocally, TOP_LEVEL_PATH, @@ -145,6 +146,16 @@ const requiresMigration = async (ctx: Ctx) => { } export const serveApp = async function (ctx: UserCtx) { + if (ctx.url.includes("apple-touch-icon")) { + ctx.redirect("/builder/bblogo.png") + return + } + // no app ID found, cannot serve - return message instead + if (!context.getAppId()) { + ctx.body = "No content found - requires app ID" + return + } + const needMigrations = await requiresMigration(ctx) const bbHeaderEmbed = diff --git a/packages/server/src/api/routes/tests/static.spec.ts b/packages/server/src/api/routes/tests/static.spec.ts index 62b72b2b8f..c2808603e9 100644 --- a/packages/server/src/api/routes/tests/static.spec.ts +++ b/packages/server/src/api/routes/tests/static.spec.ts @@ -152,4 +152,22 @@ describe("/static", () => { expect(res.body.builderPreview).toBe(true) }) }) + + describe("/", () => { + it("should move permanently from base call (public call)", async () => { + const res = await request.get(`/`) + expect(res.status).toEqual(301) + expect(res.text).toEqual( + `Redirecting to /builder.` + ) + }) + + it("should not error when trying to get 'apple-touch-icon.png' (public call)", async () => { + const res = await request.get(`/apple-touch-icon.png`) + expect(res.status).toEqual(302) + expect(res.text).toEqual( + `Redirecting to /builder/bblogo.png.` + ) + }) + }) }) diff --git a/packages/server/src/sdk/app/applications/applications.ts b/packages/server/src/sdk/app/applications/applications.ts index 07e303ccdd..1a705a211e 100644 --- a/packages/server/src/sdk/app/applications/applications.ts +++ b/packages/server/src/sdk/app/applications/applications.ts @@ -25,10 +25,12 @@ export async function fetch(status: AppStatus, user: ContextUser) { const all = status === AppStatus.ALL let apps = (await dbCore.getAllApps({ dev, all })) as App[] - const enrichedUser = await groups.enrichUserRolesFromGroups({ + // need to type this correctly - add roles back in to convert from ContextUser to User + const completeUser: User = { ...user, - roles: user.roles || {}, - }) + roles: user?.roles || {}, + } + const enrichedUser = await groups.enrichUserRolesFromGroups(completeUser) apps = filterAppList(enrichedUser, apps) const appIds = apps From dc1389b8fbc1a7e281dc85db4a45b64d613cf8db Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 30 Oct 2024 17:39:48 +0000 Subject: [PATCH 2/2] PR comment and linting. --- packages/server/src/api/controllers/static/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/static/index.ts b/packages/server/src/api/controllers/static/index.ts index b90d24c9b1..daf7b9b25c 100644 --- a/packages/server/src/api/controllers/static/index.ts +++ b/packages/server/src/api/controllers/static/index.ts @@ -6,7 +6,6 @@ import { ObjectStoreBuckets } from "../../../constants" import { processString } from "@budibase/string-templates" import { loadHandlebarsFile, - streamFile, NODE_MODULES_PATH, shouldServeLocally, TOP_LEVEL_PATH, @@ -146,7 +145,7 @@ const requiresMigration = async (ctx: Ctx) => { } export const serveApp = async function (ctx: UserCtx) { - if (ctx.url.includes("apple-touch-icon")) { + if (ctx.url.includes("apple-touch-icon.png")) { ctx.redirect("/builder/bblogo.png") return }