2020-05-07 11:53:34 +02:00
|
|
|
const Router = require("@koa/router")
|
|
|
|
const controller = require("../controllers/static")
|
2020-05-11 16:42:42 +02:00
|
|
|
const { budibaseTempDir } = require("../../utilities/budibaseDir")
|
2020-05-18 07:40:29 +02:00
|
|
|
const env = require("../../environment")
|
2020-09-15 17:22:13 +02:00
|
|
|
const authorized = require("../../middleware/authorized")
|
|
|
|
const { BUILDER } = require("../../utilities/accessLevels")
|
2020-04-14 16:14:57 +02:00
|
|
|
|
2020-05-07 11:53:34 +02:00
|
|
|
const router = Router()
|
2020-04-14 16:14:57 +02:00
|
|
|
|
2020-05-18 07:40:29 +02:00
|
|
|
router.param("file", async (file, ctx, next) => {
|
|
|
|
ctx.file = file && file.includes(".") ? file : "index.html"
|
|
|
|
|
|
|
|
// Serving the client library from your local dir in dev
|
|
|
|
if (ctx.isDev && ctx.file.startsWith("budibase-client")) {
|
|
|
|
ctx.devPath = budibaseTempDir()
|
|
|
|
}
|
2020-05-06 13:17:15 +02:00
|
|
|
|
2020-05-18 07:40:29 +02:00
|
|
|
await next()
|
|
|
|
})
|
2020-05-06 13:17:15 +02:00
|
|
|
|
2020-05-18 07:40:29 +02:00
|
|
|
if (env.NODE_ENV !== "production") {
|
|
|
|
router.get("/_builder/:file*", controller.serveBuilder)
|
|
|
|
}
|
|
|
|
|
|
|
|
router
|
2020-09-15 17:22:13 +02:00
|
|
|
.post("/api/files/process", authorized(BUILDER), controller.processLocalFileUpload)
|
2020-06-12 21:42:55 +02:00
|
|
|
.get("/componentlibrary", controller.serveComponentLibrary)
|
|
|
|
.get("/assets/:file*", controller.serveAppAsset)
|
2020-09-15 17:22:13 +02:00
|
|
|
.get("/attachments/:file*", controller.serveAttachment)
|
2020-06-12 21:42:55 +02:00
|
|
|
.get("/:appId/:path*", controller.serveApp)
|
2020-04-14 16:14:57 +02:00
|
|
|
|
2020-05-07 11:53:34 +02:00
|
|
|
module.exports = router
|