2020-12-14 19:31:48 +01:00
|
|
|
const CouchDB = require("../../db")
|
|
|
|
const { BUILDER_CONFIG_DB, HOSTING_DOC } = require("../../constants")
|
|
|
|
const {
|
|
|
|
getHostingInfo,
|
|
|
|
HostingTypes,
|
|
|
|
getAppServerUrl,
|
|
|
|
} = 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)
|
|
|
|
const { type, appServerUrl, objectStoreUrl, useHttps } = ctx.request.body
|
|
|
|
if (type === HostingTypes.CLOUD) {
|
|
|
|
ctx.throw(400, "Cannot update Cloud hosting information")
|
|
|
|
}
|
2020-12-15 17:41:55 +01:00
|
|
|
const response = await db.put({
|
2020-12-14 19:31:48 +01:00
|
|
|
_id: HOSTING_DOC,
|
|
|
|
type,
|
|
|
|
appServerUrl,
|
|
|
|
objectStoreUrl,
|
|
|
|
useHttps,
|
|
|
|
})
|
2020-12-15 17:41:55 +01:00
|
|
|
ctx.body = response
|
2020-12-14 19:31:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.fetch = async ctx => {
|
|
|
|
ctx.body = await getHostingInfo()
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.fetchUrls = async ctx => {
|
|
|
|
ctx.body = {
|
|
|
|
appServer: getAppServerUrl(ctx.appId),
|
|
|
|
}
|
|
|
|
}
|