Skip to content

Commit

Permalink
Merge pull request #14923 from Budibase/fix/migration-issue
Browse files Browse the repository at this point in the history
Fix builder serve endpoint error rate
  • Loading branch information
mike12345567 authored Oct 30, 2024
2 parents 15bfa29 + dc1389b commit 6699c44
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/server/src/api/controllers/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ const requiresMigration = async (ctx: Ctx) => {
}

export const serveApp = async function (ctx: UserCtx) {
if (ctx.url.includes("apple-touch-icon.png")) {
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 =
Expand Down
18 changes: 18 additions & 0 deletions packages/server/src/api/routes/tests/static.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="/builder">/builder</a>.`
)
})

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 <a href="/builder/bblogo.png">/builder/bblogo.png</a>.`
)
})
})
})
8 changes: 5 additions & 3 deletions packages/server/src/sdk/app/applications/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6699c44

Please sign in to comment.