1
0
Fork 0
mirror of synced 2024-09-19 18:59:06 +12:00
budibase/packages/server/api/controllers/static.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

const send = require("koa-send");
const { resolve, join } = require("path")
const { homedir } = require("os");
exports.serveBuilder = async function(ctx) {
2020-05-06 23:17:15 +12:00
let builderPath = resolve(process.cwd(), "builder")
await send(ctx, ctx.file, { root: ctx.devPath || builderPath })
}
exports.serveApp = async function(ctx) {
2020-05-03 22:33:20 +12:00
// TODO: update homedir stuff to wherever budi is run
// default to homedir
const appPath = resolve(
homedir(),
".budibase",
ctx.params.appId,
"public",
ctx.isAuthenticated ? "main" : "unauthenticated"
);
2020-05-06 23:17:15 +12:00
await send(ctx, ctx.file, { root: ctx.devPath || appPath })
}
exports.serveComponentLibrary = async function(ctx) {
2020-05-06 23:17:15 +12:00
// TODO: update homedir stuff to wherever budi is run
// default to homedir
let componentLibraryPath = resolve(
homedir(),
".budibase",
ctx.params.appId,
"node_modules",
decodeURI(ctx.query.library),
"dist"
);
2020-05-06 23:17:15 +12:00
if (ctx.isDev) {
componentLibraryPath = join(
"/tmp",
".budibase",
decodeURI(ctx.query.library),
"dist"
);
}
await send(ctx, "/index.js", { root: componentLibraryPath })
}