budibase/packages/server/api/controllers/static.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

const send = require("koa-send");
const { resolve } = require("path")
const { homedir } = require("os");
exports.serveBuilder = async function(ctx) {
2020-05-03 12:33:20 +02:00
const builderPath = resolve(process.cwd(), "builder")
await send(ctx, ctx.file, { root: builderPath })
}
exports.serveApp = async function(ctx) {
2020-05-03 12:33:20 +02: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"
);
// TODO: Hook up to JWT auth in real app
// TODO: serve CSS and other assets
// resolve unauthenticated page if user not authenticated
// resolve main page if user authenticated
2020-05-03 12:33:20 +02:00
await send(ctx, "/index.html", { root: appPath })
}
exports.serveComponentLibrary = async function(ctx) {
2020-05-03 12:33:20 +02:00
// TODO: update homedir stuff to wherever budi is run
// default to homedir
const componentLibraryPath = resolve(
homedir(),
".budibase",
ctx.params.appId,
"node_modules",
decodeURI(ctx.query.library),
"dist"
);
await send(ctx, "/index.js", { root: componentLibraryPath })
}
exports.serveComponentDefinitions = async function(ctx) {
2020-05-03 12:33:20 +02:00
// TODO: update homedir stuff to wherever budi is run
// default to homedir
const componentLibraryPath = resolve(
homedir(),
".budibase",
ctx.params.appId,
"node_modules",
decodeURI(ctx.query.library),
"dist"
);
await send(ctx, "/index.js", { root: componentLibraryPath })
}