diff --git a/src/cloudron.js b/src/cloudron.js index 31d1f28f9..40b80f8f3 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -18,6 +18,7 @@ exports = module.exports = { migrate: migrate, isConfiguredSync: isConfiguredSync, + getConfigStateSync: getConfigStateSync, checkDiskSpace: checkDiskSpace, @@ -87,7 +88,8 @@ const BOX_AND_USER_TEMPLATE = { var gUpdatingDns = false, // flag for dns update reentrancy gBoxAndUserDetails = null, // cached cloudron details like region,size... - gIsConfigured = null; // cached configured state so that return value is synchronous. null means we are not initialized yet + gIsConfigured = null, // cached configured state so that return value is synchronous. null means we are not initialized yet + gConfigState = { domain: false, dns: false, tls: false }; function CloudronError(reason, errorOrMessage) { assert.strictEqual(typeof reason, 'string'); @@ -145,6 +147,10 @@ function isConfiguredSync() { return gIsConfigured === true; } +function getConfigStateSync() { + return gConfigState; +} + function isConfigured(callback) { // set of rules to see if we have the configs required for cloudron to function // note this checks for missing configs and not invalid configs @@ -204,15 +210,21 @@ function configureAdmin(callback) { nginx.configureAdmin(certFilePath, keyFilePath, ip, callback); } else { + gConfigState.domain = true; + subdomains.waitForDns(config.adminFqdn(), ip, 'A', { interval: 30000, times: 50000 }, function (error) { if (error) return callback(error); + gConfigState.dns = true; + certificates.ensureCertificate({ location: constants.ADMIN_LOCATION }, function (error, certFilePath, keyFilePath) { if (error) { // currently, this can never happen debug('Error obtaining certificate. Proceed anyway', error); return callback(); } + gConfigState.tls = true; + nginx.configureAdmin(certFilePath, keyFilePath, config.adminFqdn(), callback); }); }); diff --git a/src/routes/cloudron.js b/src/routes/cloudron.js index 1634adb82..b3edf01df 100644 --- a/src/routes/cloudron.js +++ b/src/routes/cloudron.js @@ -101,14 +101,7 @@ function dnsSetup(req, res, next) { } function dnsReady(req, res, next) { - if (config.provider() === 'caas') return next(new HttpError(410, 'Not availabe for caas')); - - if (!config.fqdn()) return next(new HttpSuccess(200, { domain: false, ssl: false, dns: false })); - if (!certificates.adminCertificateExists()) return next(new HttpSuccess(200, { domain: true, ssl: false, dns: false })); - - // TODO also check for DNS - - next(new HttpSuccess(200, { domain: true, ssl: true, dns: false })); + next(new HttpSuccess(200, cloudron.getConfigStateSync())); } function setupTokenAuth(req, res, next) {