2020-12-14 19:31:48 +01:00
|
|
|
const CouchDB = require("../../db")
|
|
|
|
const { BUILDER_CONFIG_DB, HOSTING_DOC } = require("../../constants")
|
|
|
|
const {
|
|
|
|
getHostingInfo,
|
2021-01-14 18:01:31 +01:00
|
|
|
getDeployedApps,
|
2020-12-14 19:31:48 +01:00
|
|
|
HostingTypes,
|
2020-12-18 13:54:20 +01:00
|
|
|
getAppUrl,
|
2020-12-14 19:31:48 +01:00
|
|
|
} = require("../../utilities/builder/hosting")
|
|
|
|
|
|
|
|
exports.fetchInfo = async ctx => {
|
|
|
|
ctx.body = {
|
|
|
|
types: Object.values(HostingTypes),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.save = async ctx => {
|
|
|
|
const db = new CouchDB(BUILDER_CONFIG_DB)
|
2020-12-15 18:27:45 +01:00
|
|
|
const { type } = ctx.request.body
|
2021-01-06 17:58:29 +01:00
|
|
|
if (type === HostingTypes.CLOUD && ctx.request.body._rev) {
|
|
|
|
ctx.body = await db.remove({
|
|
|
|
...ctx.request.body,
|
|
|
|
_id: HOSTING_DOC,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
ctx.body = await db.put({
|
|
|
|
...ctx.request.body,
|
|
|
|
_id: HOSTING_DOC,
|
|
|
|
})
|
2020-12-14 19:31:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.fetch = async ctx => {
|
|
|
|
ctx.body = await getHostingInfo()
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.fetchUrls = async ctx => {
|
|
|
|
ctx.body = {
|
2020-12-18 13:54:20 +01:00
|
|
|
app: await getAppUrl(ctx.appId),
|
2020-12-14 19:31:48 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-14 18:01:31 +01:00
|
|
|
|
|
|
|
exports.getDeployedApps = async ctx => {
|
|
|
|
ctx.body = await getDeployedApps()
|
|
|
|
}
|