Merge pull request #15833 from Budibase/fix/asset-performance
Load CSS/image assets without going through middlewares
This commit is contained in:
commit
fd8aa8b7a6
|
@ -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 })
|
||||||
|
}
|
|
@ -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 (
|
export const uploadFile = async function (
|
||||||
ctx: Ctx<void, ProcessAttachmentResponse>
|
ctx: Ctx<void, ProcessAttachmentResponse>
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { middleware as pro } from "@budibase/pro"
|
||||||
import { apiEnabled, automationsEnabled } from "../features"
|
import { apiEnabled, automationsEnabled } from "../features"
|
||||||
import migrations from "../middleware/appMigrations"
|
import migrations from "../middleware/appMigrations"
|
||||||
import { automationQueue } from "../automations"
|
import { automationQueue } from "../automations"
|
||||||
|
import { serveBuilderAssets } from "./controllers/assets"
|
||||||
|
|
||||||
export { shutdown } from "./routes/public"
|
export { shutdown } from "./routes/public"
|
||||||
const compress = require("koa-compress")
|
const compress = require("koa-compress")
|
||||||
|
@ -44,6 +45,11 @@ if (apiEnabled()) {
|
||||||
)
|
)
|
||||||
// re-direct before any middlewares occur
|
// re-direct before any middlewares occur
|
||||||
.redirect("/", "/builder")
|
.redirect("/", "/builder")
|
||||||
|
|
||||||
|
// send assets before middleware
|
||||||
|
router.get("/builder/:file*", serveBuilderAssets)
|
||||||
|
|
||||||
|
router
|
||||||
.use(
|
.use(
|
||||||
auth.buildAuthMiddleware([], {
|
auth.buildAuthMiddleware([], {
|
||||||
publicAllowed: true,
|
publicAllowed: true,
|
||||||
|
|
|
@ -29,7 +29,6 @@ router.param("file", async (file: any, ctx: any, next: any) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/builder/:file*", controller.serveBuilder)
|
|
||||||
.get("/api/assets/client", controller.serveClientLibrary)
|
.get("/api/assets/client", controller.serveClientLibrary)
|
||||||
.post("/api/attachments/process", authorized(BUILDER), controller.uploadFile)
|
.post("/api/attachments/process", authorized(BUILDER), controller.uploadFile)
|
||||||
.post("/api/beta/:feature", controller.toggleBetaUiFeature)
|
.post("/api/beta/:feature", controller.toggleBetaUiFeature)
|
||||||
|
|
Loading…
Reference in New Issue