move appstore urls into appstore.js

This commit is contained in:
Girish Ramakrishnan
2023-08-04 15:34:38 +05:30
parent 37ae142a16
commit fb9d8c23e1
10 changed files with 128 additions and 128 deletions
-24
View File
@@ -75,7 +75,6 @@ exports = module.exports = {
getExec,
checkManifestConstraints,
downloadManifest,
canAutoupdateApp,
autoupdateApps,
@@ -185,7 +184,6 @@ const appstore = require('./appstore.js'),
settings = require('./settings.js'),
shell = require('./shell.js'),
storage = require('./storage.js'),
superagent = require('superagent'),
system = require('./system.js'),
tasks = require('./tasks.js'),
tgz = require('./backupformat/tgz.js'),
@@ -1141,28 +1139,6 @@ async function getTask(app) {
return await tasks.get(app.taskId);
}
async function downloadManifest(appStoreId, manifest) {
if (!appStoreId && !manifest) throw new BoxError(BoxError.BAD_FIELD, 'Neither manifest nor appStoreId provided');
if (!appStoreId) return { appStoreId: '', manifest };
const parts = appStoreId.split('@');
const url = settings.apiServerOrigin() + '/api/v1/apps/' + parts[0] + (parts[1] ? '/versions/' + parts[1] : '');
debug('downloading manifest from %s', url);
const [error, response] = await safe(superagent.get(url).timeout(30 * 1000).ok(() => true));
if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, 'Network error downloading manifest:' + error.message);
if (response.status !== 200) throw new BoxError(BoxError.NOT_FOUND, `Failed to get app info from store. status: ${response.status} text: ${response.text}`);
if (!response.body.manifest || typeof response.body.manifest !== 'object') throw new BoxError(BoxError.NOT_FOUND, `Missing manifest. Failed to get app info from store. status: ${response.status} text: ${response.text}`);
return { appStoreId: parts[0], manifest: response.body.manifest };
}
function mailboxNameForSubdomain(subdomain, manifest) {
if (subdomain) return `${subdomain}.app`;
if (manifest.title) return manifest.title.toLowerCase().replace(/[^a-zA-Z0-9]/g, '') + '.app';
+75 -12
View File
@@ -3,9 +3,15 @@
exports = module.exports = {
getFeatures,
getApiServerOrigin,
getWebServerOrigin,
getConsoleServerOrigin,
downloadManifest,
getApps,
getApp,
getAppVersion,
downloadIcon,
registerWithLoginCredentials,
updateCloudron,
@@ -23,6 +29,7 @@ exports = module.exports = {
createTicket,
// exported for tests
_setApiServerOrigin: setApiServerOrigin,
_unregister: unregister
};
@@ -35,6 +42,7 @@ const apps = require('./apps.js'),
network = require('./network.js'),
path = require('path'),
paths = require('./paths.js'),
promiseRetry = require('./promise-retry.js'),
safe = require('safetydance'),
semver = require('semver'),
settings = require('./settings.js'),
@@ -65,12 +73,29 @@ function getFeatures() {
return gFeatures;
}
async function getApiServerOrigin() {
return await settings.get(settings.API_SERVER_ORIGIN_KEY) || 'https://api.cloudron.io';
}
async function setApiServerOrigin(origin) {
assert.strictEqual(typeof origin, 'string');
await settings.set(settings.API_SERVER_ORIGIN_KEY, origin);
}
async function getWebServerOrigin() {
return await settings.get(settings.WEB_SERVER_ORIGIN_KEY) || 'https://cloudron.io';
}
async function getConsoleServerOrigin() {
return await settings.get(settings.CONSOLE_SERVER_ORIGIN_KEY) || 'https://console.cloudron.io';
}
async function login(email, password, totpToken) {
assert.strictEqual(typeof email, 'string');
assert.strictEqual(typeof password, 'string');
assert.strictEqual(typeof totpToken, 'string');
const [error, response] = await safe(superagent.post(`${settings.apiServerOrigin()}/api/v1/login`)
const [error, response] = await safe(superagent.post(`${await getApiServerOrigin()}/api/v1/login`)
.send({ email, password, totpToken })
.timeout(30 * 1000)
.ok(() => true));
@@ -87,7 +112,7 @@ async function registerUser(email, password) {
assert.strictEqual(typeof email, 'string');
assert.strictEqual(typeof password, 'string');
const [error, response] = await safe(superagent.post(`${settings.apiServerOrigin()}/api/v1/register_user`)
const [error, response] = await safe(superagent.post(`${await getApiServerOrigin()}/api/v1/register_user`)
.send({ email, password, utmSource: 'cloudron-dashboard' })
.timeout(30 * 1000)
.ok(() => true));
@@ -110,7 +135,7 @@ async function getSubscription() {
const token = await settings.get(settings.APPSTORE_API_TOKEN_KEY);
if (!token) throw new BoxError(BoxError.LICENSE_ERROR, 'Missing token');
const [error, response] = await safe(superagent.get(`${settings.apiServerOrigin()}/api/v1/subscription`)
const [error, response] = await safe(superagent.get(`${await getApiServerOrigin()}/api/v1/subscription`)
.query({ accessToken: token })
.timeout(30 * 1000)
.ok(() => true));
@@ -140,7 +165,7 @@ async function purchaseApp(data) {
const token = await settings.get(settings.APPSTORE_API_TOKEN_KEY);
if (!token) throw new BoxError(BoxError.LICENSE_ERROR, 'Missing token');
const [error, response] = await safe(superagent.post(`${settings.apiServerOrigin()}/api/v1/cloudronapps`)
const [error, response] = await safe(superagent.post(`${await getApiServerOrigin()}/api/v1/cloudronapps`)
.send(data)
.query({ accessToken: token })
.timeout(30 * 1000)
@@ -162,7 +187,7 @@ async function unpurchaseApp(appId, data) {
const token = await settings.get(settings.APPSTORE_API_TOKEN_KEY);
if (!token) throw new BoxError(BoxError.LICENSE_ERROR, 'Missing token');
const url = `${settings.apiServerOrigin()}/api/v1/cloudronapps/${appId}`;
const url = `${await getApiServerOrigin()}/api/v1/cloudronapps/${appId}`;
let [error, response] = await safe(superagent.get(url)
.query({ accessToken: token })
@@ -197,7 +222,7 @@ async function getBoxUpdate(options) {
automatic: options.automatic
};
const [error, response] = await safe(superagent.get(`${settings.apiServerOrigin()}/api/v1/boxupdate`)
const [error, response] = await safe(superagent.get(`${await getApiServerOrigin()}/api/v1/boxupdate`)
.query(query)
.timeout(30 * 1000)
.ok(() => true));
@@ -239,7 +264,7 @@ async function getAppUpdate(app, options) {
automatic: options.automatic
};
const [error, response] = await safe(superagent.get(`${settings.apiServerOrigin()}/api/v1/appupdate`)
const [error, response] = await safe(superagent.get(`${await getApiServerOrigin()}/api/v1/appupdate`)
.query(query)
.timeout(30 * 1000)
.ok(() => true));
@@ -271,7 +296,7 @@ async function registerCloudron(data) {
const { domain, accessToken, version, existingApps } = data;
const [error, response] = await safe(superagent.post(`${settings.apiServerOrigin()}/api/v1/register_cloudron`)
const [error, response] = await safe(superagent.post(`${await getApiServerOrigin()}/api/v1/register_cloudron`)
.send({ domain, accessToken, version, existingApps })
.timeout(30 * 1000)
.ok(() => true));
@@ -302,7 +327,7 @@ async function updateCloudron(data) {
accessToken: token
};
const [error, response] = await safe(superagent.post(`${settings.apiServerOrigin()}/api/v1/update_cloudron`)
const [error, response] = await safe(superagent.post(`${await getApiServerOrigin()}/api/v1/update_cloudron`)
.query(query)
.send({ domain })
.timeout(30 * 1000)
@@ -354,7 +379,7 @@ async function createTicket(info, auditSource) {
info.app = info.appId ? await apps.get(info.appId) : null;
info.supportEmail = constants.SUPPORT_EMAIL; // destination address for tickets
const request = superagent.post(`${settings.apiServerOrigin()}/api/v1/ticket`)
const request = superagent.post(`${await getApiServerOrigin()}/api/v1/ticket`)
.query({ accessToken: token })
.timeout(30 * 1000)
.ok(() => true);
@@ -382,11 +407,33 @@ async function createTicket(info, auditSource) {
return { message: `An email was sent to ${constants.SUPPORT_EMAIL}. We will get back shortly!` };
}
async function downloadManifest(appStoreId, manifest) {
if (!appStoreId && !manifest) throw new BoxError(BoxError.BAD_FIELD, 'Neither manifest nor appStoreId provided');
if (!appStoreId) return { appStoreId: '', manifest };
const parts = appStoreId.split('@');
const url = await getApiServerOrigin() + '/api/v1/apps/' + parts[0] + (parts[1] ? '/versions/' + parts[1] : '');
debug(`downloading manifest from ${url}`);
const [error, response] = await safe(superagent.get(url).timeout(30 * 1000).ok(() => true));
if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, 'Network error downloading manifest:' + error.message);
if (response.status !== 200) throw new BoxError(BoxError.NOT_FOUND, `Failed to get app info from store. status: ${response.status} text: ${response.text}`);
if (!response.body.manifest || typeof response.body.manifest !== 'object') throw new BoxError(BoxError.NOT_FOUND, `Missing manifest. Failed to get app info from store. status: ${response.status} text: ${response.text}`);
return { appStoreId: parts[0], manifest: response.body.manifest };
}
async function getApps() {
const token = await settings.get(settings.APPSTORE_API_TOKEN_KEY);
if (!token) throw new BoxError(BoxError.LICENSE_ERROR, 'Missing token');
const [error, response] = await safe(superagent.get(`${settings.apiServerOrigin()}/api/v1/apps`)
const [error, response] = await safe(superagent.get(`${await getApiServerOrigin()}/api/v1/apps`)
.query({ accessToken: token, boxVersion: constants.VERSION, unstable: true })
.timeout(30 * 1000)
.ok(() => true));
@@ -406,7 +453,7 @@ async function getAppVersion(appId, version) {
const token = await settings.get(settings.APPSTORE_API_TOKEN_KEY);
if (!token) throw new BoxError(BoxError.LICENSE_ERROR, 'Missing token');
let url = `${settings.apiServerOrigin()}/api/v1/apps/${appId}`;
let url = `${await getApiServerOrigin()}/api/v1/apps/${appId}`;
if (version !== 'latest') url += `/versions/${version}`;
const [error, response] = await safe(superagent.get(url)
@@ -427,3 +474,19 @@ async function getApp(appId) {
return await getAppVersion(appId, 'latest');
}
async function downloadIcon(appStoreId, version) {
const iconUrl = `${await getApiServerOrigin()}/api/v1/apps/${appStoreId}/versions/${version}/icon`;
return await promiseRetry({ times: 10, interval: 5000, debug }, async function () {
const [networkError, response] = await safe(superagent.get(iconUrl)
.buffer(true)
.timeout(30 * 1000)
.ok(() => true));
if (networkError) throw new BoxError(BoxError.NETWORK_ERROR, `Network error downloading icon : ${networkError.message}`);
if (response.status !== 200) return; // ignore error. this can also happen for apps installed with cloudron-cli
return response.body;
});
}
+3 -15
View File
@@ -13,6 +13,7 @@ exports = module.exports = {
};
const apps = require('./apps.js'),
appstore = require('./appstore.js'),
assert = require('assert'),
AuditSource = require('./auditsource.js'),
backuptask = require('./backuptask.js'),
@@ -35,9 +36,7 @@ const apps = require('./apps.js'),
reverseProxy = require('./reverseproxy.js'),
safe = require('safetydance'),
services = require('./services.js'),
settings = require('./settings.js'),
shell = require('./shell.js'),
superagent = require('superagent'),
_ = require('underscore');
const MV_VOLUME_CMD = path.join(__dirname, 'scripts/mvvolume.sh'),
@@ -206,19 +205,8 @@ async function downloadIcon(app) {
debug(`downloadIcon: Downloading icon of ${app.appStoreId}@${app.manifest.version}`);
const iconUrl = settings.apiServerOrigin() + '/api/v1/apps/' + app.appStoreId + '/versions/' + app.manifest.version + '/icon';
await promiseRetry({ times: 10, interval: 5000, debug }, async function () {
const [networkError, response] = await safe(superagent.get(iconUrl)
.buffer(true)
.timeout(30 * 1000)
.ok(() => true));
if (networkError) throw new BoxError(BoxError.NETWORK_ERROR, `Network error downloading icon : ${networkError.message}`);
if (response.status !== 200) return; // ignore error. this can also happen for apps installed with cloudron-cli
await updateApp(app, { appStoreIcon: response.body });
});
const appStoreIcon = await appstore.downloadIcon(app.appStoreId, app.manifest.version);
await updateApp(app, { appStoreIcon });
}
async function waitForDnsPropagation(app) {
+3 -3
View File
@@ -136,9 +136,9 @@ async function getConfig() {
// be picky about what we send out here since this is sent for 'normal' users as well
return {
apiServerOrigin: settings.apiServerOrigin(),
webServerOrigin: settings.webServerOrigin(),
consoleServerOrigin: settings.consoleServerOrigin(),
apiServerOrigin: await appstore.getApiServerOrigin(),
webServerOrigin: await appstore.getWebServerOrigin(),
consoleServerOrigin: await appstore.getConsoleServerOrigin(),
adminDomain: settings.dashboardDomain(),
adminFqdn: settings.dashboardFqdn(),
mailFqdn: settings.mailFqdn(),
+4 -3
View File
@@ -9,7 +9,8 @@ exports = module.exports = {
provider
};
const assert = require('assert'),
const appstore = require('./appstore.js'),
assert = require('assert'),
backups = require('./backups.js'),
backuptask = require('./backuptask.js'),
BoxError = require('./boxerror.js'),
@@ -252,8 +253,8 @@ async function getStatus() {
return Object.assign({
version: constants.VERSION,
apiServerOrigin: settings.apiServerOrigin(), // used by CaaS tool
webServerOrigin: settings.webServerOrigin(), // used by CaaS tool
apiServerOrigin: await appstore.getApiServerOrigin(), // used by CaaS tool
webServerOrigin: await appstore.getWebServerOrigin(), // used by CaaS tool
cloudronName: await branding.getCloudronName(),
footer: await branding.renderFooter(),
adminFqdn: settings.dashboardDomain() ? settings.dashboardFqdn() : null,
+2 -1
View File
@@ -67,6 +67,7 @@ exports = module.exports = {
};
const apps = require('../apps.js'),
appstore = require('../appstore.js'),
assert = require('assert'),
AuditSource = require('../auditsource.js'),
BoxError = require('../boxerror.js'),
@@ -180,7 +181,7 @@ async function install(req, res, next) {
if ('enableTurn' in data && typeof data.enableTurn !== 'boolean') return next(new HttpError(400, 'enableTurn must be boolean'));
let [error, result] = await safe(apps.downloadManifest(data.appStoreId, data.manifest));
let [error, result] = await safe(appstore.downloadManifest(data.appStoreId, data.manifest));
if (error) return next(BoxError.toHttpError(error));
if (result.appStoreId === constants.PROXY_APP_APPSTORE_ID && typeof data.upstreamUri !== 'string') return next(new HttpError(400, 'upstreamUri must be a non empty string'));
+12 -12
View File
@@ -27,7 +27,7 @@ describe('Appstore Apps API', function () {
});
it('cannot get app with bad token', async function () {
const scope1 = nock(settings.apiServerOrigin())
const scope1 = nock(await appstore.getApiServerOrigin())
.get(`/api/v1/apps/org.wordpress.cloudronapp?accessToken=${appstoreToken}`)
.reply(403, {});
@@ -40,7 +40,7 @@ describe('Appstore Apps API', function () {
});
it('can list apps', async function () {
const scope1 = nock(settings.apiServerOrigin())
const scope1 = nock(await appstore.getApiServerOrigin())
.get(`/api/v1/apps?accessToken=${appstoreToken}&boxVersion=${constants.VERSION}&unstable=true`, () => true)
.reply(200, { apps: [] });
@@ -52,7 +52,7 @@ describe('Appstore Apps API', function () {
});
it('can get app', async function () {
const scope1 = nock(settings.apiServerOrigin())
const scope1 = nock(await appstore.getApiServerOrigin())
.get(`/api/v1/apps/org.wordpress.cloudronapp?accessToken=${appstoreToken}`, () => true)
.reply(200, { apps: [] });
@@ -64,7 +64,7 @@ describe('Appstore Apps API', function () {
});
it('can get app version', async function () {
const scope1 = nock(settings.apiServerOrigin())
const scope1 = nock(await appstore.getApiServerOrigin())
.get(`/api/v1/apps/org.wordpress.cloudronapp/versions/3.4.2?accessToken=${appstoreToken}`, () => true)
.reply(200, { apps: [] });
@@ -84,15 +84,15 @@ describe('Appstore Cloudron Registration API - existing user', function () {
after(cleanup);
it('can setup subscription', async function () {
const scope1 = nock(settings.apiServerOrigin())
const scope1 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/register_user', (body) => body.email && body.password && body.utmSource)
.reply(201, {});
const scope2 = nock(settings.apiServerOrigin())
const scope2 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/login', (body) => body.email && body.password)
.reply(200, { userId: 'userId', accessToken: 'SECRET_TOKEN' });
const scope3 = nock(settings.apiServerOrigin())
const scope3 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/register_cloudron', (body) => !!body.domain && body.accessToken === 'SECRET_TOKEN')
.reply(201, { cloudronId: 'cid', cloudronToken: 'CLOUDRON_TOKEN' });
@@ -111,7 +111,7 @@ describe('Appstore Cloudron Registration API - existing user', function () {
});
it('can get subscription', async function () {
const scope1 = nock(settings.apiServerOrigin())
const scope1 = nock(await appstore.getApiServerOrigin())
.get('/api/v1/subscription?accessToken=CLOUDRON_TOKEN', () => true)
.reply(200, { subscription: { plan: { id: 'free' } }, email: 'test@cloudron.io' });
@@ -133,15 +133,15 @@ describe('Appstore Cloudron Registration API - new user signup', function () {
after(cleanup);
it('can setup subscription', async function () {
const scope1 = nock(settings.apiServerOrigin())
const scope1 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/register_user', (body) => body.email && body.password && body.utmSource)
.reply(201, {});
const scope2 = nock(settings.apiServerOrigin())
const scope2 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/login', (body) => body.email && body.password)
.reply(200, { userId: 'userId', accessToken: 'SECRET_TOKEN' });
const scope3 = nock(settings.apiServerOrigin())
const scope3 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/register_cloudron', (body) => !!body.domain && body.accessToken === 'SECRET_TOKEN')
.reply(201, { cloudronId: 'cid', cloudronToken: 'CLOUDRON_TOKEN' });
@@ -158,7 +158,7 @@ describe('Appstore Cloudron Registration API - new user signup', function () {
});
it('can get subscription', async function () {
const scope1 = nock(settings.apiServerOrigin())
const scope1 = nock(await appstore.getApiServerOrigin())
.get('/api/v1/subscription?accessToken=CLOUDRON_TOKEN', () => true)
.reply(200, { subscription: { plan: { id: 'free' } }, email: 'test@cloudron.io' });
+3 -2
View File
@@ -1,6 +1,7 @@
'use strict';
const constants = require('../../constants.js'),
const appstore = require('../../appstore.js'),
constants = require('../../constants.js'),
database = require('../../database.js'),
expect = require('expect.js'),
fs = require('fs'),
@@ -60,7 +61,7 @@ async function setupServer() {
await database._clear();
await oidc.stop();
await database.initialize();
await settings._setApiServerOrigin(exports.mockApiServerOrigin);
await appstore._setApiServerOrigin(exports.mockApiServerOrigin);
await server.start();
}
+24 -55
View File
@@ -4,9 +4,6 @@ exports = module.exports = {
initCache,
// these values come from the cache
apiServerOrigin,
webServerOrigin,
consoleServerOrigin,
dashboardDomain,
setDashboardLocation,
setMailLocation,
@@ -26,50 +23,40 @@ exports = module.exports = {
getBlob,
setBlob,
// booleans. if you add an entry here, be sure to fix list()
DYNAMIC_DNS_KEY: 'dynamic_dns',
// json. if you add an entry here, be sure to fix list()
BACKUP_CONFIG_KEY: 'backup_config',
BACKUP_POLICY_KEY: 'backup_policy',
SERVICES_CONFIG_KEY: 'services_config',
EXTERNAL_LDAP_KEY: 'external_ldap_config',
DIRECTORY_SERVER_KEY: 'directory_server_config',
REGISTRY_CONFIG_KEY: 'registry_config',
IPV4_CONFIG_KEY: 'ipv4_config',
SUPPORT_CONFIG_KEY: 'support_config',
PROFILE_CONFIG_KEY: 'profile_config',
GHOSTS_CONFIG_KEY: 'ghosts_config',
REVERSE_PROXY_CONFIG_KEY: 'reverseproxy_config',
IPV6_CONFIG_KEY: 'ipv6_config',
// strings
AUTOUPDATE_PATTERN_KEY: 'autoupdate_pattern',
TIME_ZONE_KEY: 'time_zone',
OIDC_COOKIE_SECRET_KEY: 'cookie_secret',
CLOUDRON_NAME_KEY: 'cloudron_name',
LANGUAGE_KEY: 'language',
CLOUDRON_ID_KEY: 'cloudron_id',
APPSTORE_API_TOKEN_KEY: 'appstore_api_token',
APPSTORE_WEB_TOKEN_KEY: 'appstore_web_token',
FIREWALL_BLOCKLIST_KEY: 'firewall_blocklist',
TRUSTED_IPS_KEY: 'trusted_ips_key',
API_SERVER_ORIGIN_KEY: 'api_server_origin',
WEB_SERVER_ORIGIN_KEY: 'web_server_origin',
AUTOUPDATE_PATTERN_KEY: 'autoupdate_pattern',
BACKUP_CONFIG_KEY: 'backup_config',
BACKUP_POLICY_KEY: 'backup_policy',
CLOUDRON_AVATAR_KEY: 'cloudron_avatar',
CLOUDRON_ID_KEY: 'cloudron_id',
CLOUDRON_NAME_KEY: 'cloudron_name',
CONSOLE_SERVER_ORIGIN_KEY: 'console_server_origin',
DASHBOARD_DOMAIN_KEY: 'admin_domain',
DASHBOARD_FQDN_KEY: 'admin_fqdn',
DIRECTORY_SERVER_KEY: 'directory_server_config',
DYNAMIC_DNS_KEY: 'dynamic_dns',
EXTERNAL_LDAP_KEY: 'external_ldap_config',
FOOTER_KEY: 'footer',
FIREWALL_BLOCKLIST_KEY: 'firewall_blocklist',
GHOSTS_CONFIG_KEY: 'ghosts_config',
IPV4_CONFIG_KEY: 'ipv4_config',
IPV6_CONFIG_KEY: 'ipv6_config',
LANGUAGE_KEY: 'language',
MAIL_DOMAIN_KEY: 'mail_domain',
MAIL_FQDN_KEY: 'mail_fqdn',
FOOTER_KEY: 'footer',
// blobs
CLOUDRON_AVATAR_KEY: 'cloudron_avatar',
OIDC_COOKIE_SECRET_KEY: 'cookie_secret',
PROFILE_CONFIG_KEY: 'profile_config',
REGISTRY_CONFIG_KEY: 'registry_config',
REVERSE_PROXY_CONFIG_KEY: 'reverseproxy_config',
SERVICES_CONFIG_KEY: 'services_config',
SUPPORT_CONFIG_KEY: 'support_config',
TIME_ZONE_KEY: 'time_zone',
TRUSTED_IPS_KEY: 'trusted_ips_key',
WEB_SERVER_ORIGIN_KEY: 'web_server_origin',
// testing
_setApiServerOrigin: setApiServerOrigin,
_clear: clear,
_set: set
};
@@ -89,10 +76,6 @@ const gDefaults = (function () {
result[exports.MAIL_DOMAIN_KEY] = '';
result[exports.MAIL_FQDN_KEY] = '';
result[exports.API_SERVER_ORIGIN_KEY] = 'https://api.cloudron.io';
result[exports.WEB_SERVER_ORIGIN_KEY] = 'https://cloudron.io';
result[exports.CONSOLE_SERVER_ORIGIN_KEY] = 'https://console.cloudron.io';
return result;
})();
@@ -165,9 +148,6 @@ async function initCache() {
const allSettings = await list();
gCache = {
apiServerOrigin: allSettings[exports.API_SERVER_ORIGIN_KEY],
webServerOrigin: allSettings[exports.WEB_SERVER_ORIGIN_KEY],
consoleServerOrigin: allSettings[exports.CONSOLE_SERVER_ORIGIN_KEY],
dashboardDomain: allSettings[exports.DASHBOARD_DOMAIN_KEY],
dashboardFqdn: allSettings[exports.DASHBOARD_FQDN_KEY],
mailDomain: allSettings[exports.MAIL_DOMAIN_KEY],
@@ -198,17 +178,6 @@ async function setMailLocation(mailDomain, mailFqdn) {
gCache.mailFqdn = mailFqdn;
}
async function setApiServerOrigin(origin) {
assert.strictEqual(typeof origin, 'string');
await set(exports.API_SERVER_ORIGIN_KEY, origin);
gCache.apiServerOrigin = origin;
}
function apiServerOrigin() { return gCache.apiServerOrigin; }
function webServerOrigin() { return gCache.webServerOrigin; }
function consoleServerOrigin() { return gCache.consoleServerOrigin; }
function dashboardDomain() { return gCache.dashboardDomain; }
function dashboardFqdn() { return gCache.dashboardFqdn; }
function mailDomain() { return gCache.mailDomain; }
+2 -1
View File
@@ -1,6 +1,7 @@
'use strict';
const apps = require('../apps.js'),
appstore = require('../appstore.js'),
constants = require('../constants.js'),
database = require('../database.js'),
domains = require('../domains.js'),
@@ -211,7 +212,7 @@ async function databaseSetup() {
await database.initialize();
await database._clear();
await settings._setApiServerOrigin(exports.mockApiServerOrigin);
await appstore._setApiServerOrigin(exports.mockApiServerOrigin);
await settings.setDashboardLocation(exports.dashboardDomain, exports.dashboardFqdn);
await settings.initCache();
}