Merge pull request #15833 from Budibase/fix/asset-performance

Load CSS/image assets without going through middlewares
This commit is contained in:
Michael Drury 2025-03-28 14:52:33 +00:00 committed by GitHub
commit fd8aa8b7a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 6 deletions

View File

@ -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<void, void>) {
const builderPath = join(TOP_LEVEL_PATH, "builder")
await send(ctx, ctx.file, { root: builderPath })
}

View File

@ -76,11 +76,6 @@ export const toggleBetaUiFeature = async function (
}
}
export const serveBuilder = async function (ctx: Ctx<void, void>) {
const builderPath = join(TOP_LEVEL_PATH, "builder")
await send(ctx, ctx.file, { root: builderPath })
}
export const uploadFile = async function (
ctx: Ctx<void, ProcessAttachmentResponse>
) {

View File

@ -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,

View File

@ -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)