diff --git a/src/routes/cloudron.js b/src/routes/cloudron.js index 6f4f8a5a1..0ecd25ab9 100644 --- a/src/routes/cloudron.js +++ b/src/routes/cloudron.js @@ -88,6 +88,9 @@ function dnsSetup(req, res, next) { if (typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required')); if (config.fqdn()) return next(new HttpError(409, 'Already setup')); + if (typeof req.body.domain !== 'string' || !req.body.domain) return next(new HttpError(400, 'domain is required')); + + config.set('fqdn', req.body.domain); settings.setDnsConfig(req.body, function (error) { if (error && error.reason === SettingsError.BAD_FIELD) return next(new HttpError(400, error.message)); diff --git a/src/settings.js b/src/settings.js index 4b0920193..1e82f9732 100644 --- a/src/settings.js +++ b/src/settings.js @@ -350,10 +350,7 @@ function setDnsConfig(dnsConfig, callback) { sysinfo.getIp(function (error, ip) { if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, 'Error getting IP:' + error.message)); - // add the domain in case we do not change it with this request - if (!dnsConfig.domain) dnsConfig.domain = config.fqdn(); - - subdomains.verifyDnsConfig(dnsConfig, dnsConfig.domain, ip, function (error, result) { + subdomains.verifyDnsConfig(dnsConfig, config.fqdn(), ip, function (error, result) { if (error && error.reason === SubdomainError.ACCESS_DENIED) return callback(new SettingsError(SettingsError.BAD_FIELD, 'Error adding A record. Access denied')); if (error && error.reason === SubdomainError.NOT_FOUND) return callback(new SettingsError(SettingsError.BAD_FIELD, 'Zone not found')); if (error && error.reason === SubdomainError.EXTERNAL_ERROR) return callback(new SettingsError(SettingsError.BAD_FIELD, 'Error adding A record:' + error.message)); @@ -364,9 +361,6 @@ function setDnsConfig(dnsConfig, callback) { settingsdb.set(exports.DNS_CONFIG_KEY, JSON.stringify(result), function (error) { if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error)); - // sync the domain to the cloudron.conf - if (dnsConfig.domain) config.set('fqdn', dnsConfig.domain); - exports.events.emit(exports.DNS_CONFIG_KEY, dnsConfig); callback(null);