budibase/packages/server/middleware/routes/apps.js

37 lines
962 B
JavaScript
Raw Normal View History

2020-04-03 17:15:53 +02:00
const Router = require("@koa/router");
2020-04-06 15:05:57 +02:00
const StatusCodes = require("../../utilities/statusCodes")
2020-04-03 17:15:53 +02:00
const {
getPackageForBuilder,
getApps,
2020-04-03 18:35:20 +02:00
} = require("../../utilities/builder")
2020-04-03 17:15:53 +02:00
const router = Router();
router.get("/_builder/api/apps", async ctx => {
2020-04-06 15:05:57 +02:00
ctx.body = await getApps(ctx.config, ctx.master)
2020-04-03 17:15:53 +02:00
ctx.response.status = StatusCodes.OK
})
router.get("/_builder/api/:appname/appPackage", async ctx => {
const application = await ctx.master.getApplicationWithInstances(
ctx.params.appname
)
2020-04-06 15:05:57 +02:00
ctx.body = await getPackageForBuilder(ctx.config, application)
2020-04-03 17:15:53 +02:00
ctx.response.status = StatusCodes.OK
})
router
.post("/_builder/api/:appname/backend", async ctx => {
await saveBackend(
2020-04-06 10:09:48 +02:00
ctx.config,
2020-04-03 17:15:53 +02:00
ctx.params.appname,
ctx.request.body.appDefinition,
ctx.request.body.accessLevels
)
ctx.master.deleteLatestPackageFromCache(ctx.params.appname)
ctx.response.status = StatusCodes.OK
})
module.exports = router