reverseproxy: async'ify
This commit is contained in:
@@ -33,6 +33,7 @@ const apps = require('./apps.js'),
|
||||
constants = require('./constants.js'),
|
||||
cron = require('./cron.js'),
|
||||
debug = require('debug')('box:cloudron'),
|
||||
delay = require('delay'),
|
||||
dns = require('./dns.js'),
|
||||
domains = require('./domains.js'),
|
||||
eventlog = require('./eventlog.js'),
|
||||
@@ -89,7 +90,10 @@ function onActivated(options, callback) {
|
||||
cron.startJobs,
|
||||
// disable responding to api calls via IP to not leak domain info. this is carefully placed as the last item, so it buys
|
||||
// the UI some time to query the dashboard domain in the restore code path
|
||||
(done) => setTimeout(() => reverseProxy.writeDefaultConfig({ activated :true }, done), 30000)
|
||||
async () => {
|
||||
await delay(30000);
|
||||
await reverseProxy.writeDefaultConfig({ activated :true });
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -121,27 +125,25 @@ function runStartupTasks() {
|
||||
},
|
||||
|
||||
// always generate webadmin config since we have no versioning mechanism for the ejs
|
||||
function (callback) {
|
||||
if (!settings.dashboardDomain()) return callback();
|
||||
async function () {
|
||||
if (!settings.dashboardDomain()) return;
|
||||
|
||||
reverseProxy.writeDashboardConfig(settings.dashboardDomain(), callback);
|
||||
await reverseProxy.writeDashboardConfig(settings.dashboardDomain());
|
||||
},
|
||||
|
||||
// check activation state and start the platform
|
||||
function (callback) {
|
||||
util.callbackify(users.isActivated)(function (error, activated) {
|
||||
if (error) return callback(error);
|
||||
async function () {
|
||||
const activated = await users.isActivated();
|
||||
|
||||
// configure nginx to be reachable by IP when not activated. for the moment, the IP based redirect exists even after domain is setup
|
||||
// just in case user forgot or some network error happenned in the middle (then browser refresh takes you to activation page)
|
||||
// we remove the config as a simple security measure to not expose IP <-> domain
|
||||
if (!activated) {
|
||||
debug('runStartupTasks: not activated. generating IP based redirection config');
|
||||
return reverseProxy.writeDefaultConfig({ activated: false }, callback);
|
||||
}
|
||||
// configure nginx to be reachable by IP when not activated. for the moment, the IP based redirect exists even after domain is setup
|
||||
// just in case user forgot or some network error happenned in the middle (then browser refresh takes you to activation page)
|
||||
// we remove the config as a simple security measure to not expose IP <-> domain
|
||||
if (!activated) {
|
||||
debug('runStartupTasks: not activated. generating IP based redirection config');
|
||||
return await reverseProxy.writeDefaultConfig({ activated: false });
|
||||
}
|
||||
|
||||
onActivated({}, callback);
|
||||
});
|
||||
await util.promisify(onActivated)({});
|
||||
}
|
||||
];
|
||||
|
||||
@@ -317,7 +319,7 @@ function setDashboardDomain(domain, auditSource, callback) {
|
||||
domainsGet(domain, function (error, domainObject) {
|
||||
if (error) return callback(error);
|
||||
|
||||
reverseProxy.writeDashboardConfig(domain, function (error) {
|
||||
util.callbackify(reverseProxy.writeDashboardConfig)(domain, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
const fqdn = dns.fqdn(constants.DASHBOARD_LOCATION, domainObject);
|
||||
|
||||
Reference in New Issue
Block a user