diff --git a/packages/server/src/api/controllers/assets.ts b/packages/server/src/api/controllers/assets.ts new file mode 100644 index 0000000000..31e615a074 --- /dev/null +++ b/packages/server/src/api/controllers/assets.ts @@ -0,0 +1,10 @@ +import { join } from "../../utilities/centralPath" +import { TOP_LEVEL_PATH } from "../../utilities/fileSystem" +import { Ctx } from "@budibase/types" +import send from "koa-send" + +// this is a public endpoint with no middlewares +export const serveBuilderAssets = async function (ctx: Ctx) { + const builderPath = join(TOP_LEVEL_PATH, "builder") + await send(ctx, ctx.file, { root: builderPath }) +} diff --git a/packages/server/src/api/controllers/static/index.ts b/packages/server/src/api/controllers/static/index.ts index 3d30e601db..aac4ec5d84 100644 --- a/packages/server/src/api/controllers/static/index.ts +++ b/packages/server/src/api/controllers/static/index.ts @@ -76,11 +76,6 @@ export const toggleBetaUiFeature = async function ( } } -export const serveBuilder = async function (ctx: Ctx) { - const builderPath = join(TOP_LEVEL_PATH, "builder") - await send(ctx, ctx.file, { root: builderPath }) -} - export const uploadFile = async function ( ctx: Ctx ) { diff --git a/packages/server/src/api/index.ts b/packages/server/src/api/index.ts index 53be2b30a9..276bb7e209 100644 --- a/packages/server/src/api/index.ts +++ b/packages/server/src/api/index.ts @@ -8,6 +8,7 @@ import { middleware as pro } from "@budibase/pro" import { apiEnabled, automationsEnabled } from "../features" import migrations from "../middleware/appMigrations" import { automationQueue } from "../automations" +import { serveBuilderAssets } from "./controllers/assets" export { shutdown } from "./routes/public" const compress = require("koa-compress") @@ -44,6 +45,11 @@ if (apiEnabled()) { ) // re-direct before any middlewares occur .redirect("/", "/builder") + + // send assets before middleware + router.get("/builder/:file*", serveBuilderAssets) + + router .use( auth.buildAuthMiddleware([], { publicAllowed: true, diff --git a/packages/server/src/api/routes/static.ts b/packages/server/src/api/routes/static.ts index f331609923..8b921e7ba7 100644 --- a/packages/server/src/api/routes/static.ts +++ b/packages/server/src/api/routes/static.ts @@ -29,7 +29,6 @@ router.param("file", async (file: any, ctx: any, next: any) => { }) router - .get("/builder/:file*", controller.serveBuilder) .get("/api/assets/client", controller.serveClientLibrary) .post("/api/attachments/process", authorized(BUILDER), controller.uploadFile) .post("/api/beta/:feature", controller.toggleBetaUiFeature)