+
diff --git a/src/views/app.js b/src/views/app.js
index ffc644538..82146e149 100644
--- a/src/views/app.js
+++ b/src/views/app.js
@@ -1520,6 +1520,8 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
subdomain: '',
domain: null,
secondaryDomains: {},
+ needsOverwrite: false,
+ overwriteDns: false,
portBindings: {},
portBindingsInfo: {},
portBindingsEnabled: {},
@@ -1531,6 +1533,9 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
$scope.clone.backup = backup;
$scope.clone.domain = $scope.domains.find(function (d) { return app.domain === d.domain; }); // pre-select the app's domain
+ $scope.clone.needsOverwrite = false;
+ $scope.clone.overwriteDns = false;
+
$scope.clone.secondaryDomains = {};
app.secondaryDomains.forEach(function (sd) {
$scope.clone.secondaryDomains[sd.environmentVariable] = {
@@ -1573,28 +1578,46 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
domain: $scope.clone.domain.domain,
secondaryDomains: secondaryDomains,
portBindings: finalPortBindings,
- backupId: $scope.clone.backup.id
+ backupId: $scope.clone.backup.id,
+ overwriteDns: $scope.clone.overwriteDns
};
- Client.checkDNSRecords(data.domain, data.subdomain, function (error, result) {
- if (error) {
- Client.error(error);
- $scope.clone.busy = false;
- return;
- }
- if (result.error) {
- if (result.error.reason === ERROR.ACCESS_DENIED) {
- $scope.clone.error.location = 'DNS credentials for ' + data.domain + ' are invalid. Update it in Domains & Certs view';
- } else {
- $scope.clone.error.location = result.error.message;
+ var allDomains = [{ domain: data.domain, subdomain: data.subdomain }].concat(Object.keys(secondaryDomains).map(function (k) {
+ return {
+ domain: secondaryDomains[k].domain,
+ subdomain: secondaryDomains[k].subdomain
+ };
+ }));
+ async.eachSeries(allDomains, function (domain, callback) {
+ if ($scope.clone.overwriteDns) return callback();
+
+ Client.checkDNSRecords(domain.domain, domain.subdomain, function (error, result) {
+ if (error) return callback(error);
+
+ var fqdn = domain.subdomain + '.' + domain.domain;
+
+ if (result.error) {
+ if (result.error.reason === ERROR.ACCESS_DENIED) return callback({ type: 'provider', fqdn: fqdn, message: 'DNS credentials for ' + domain.domain + ' are invalid. Update it in Domains & Certs view' });
+ return callback({ type: 'provider', fqdn: fqdn, message: result.error.message });
}
- $scope.clone.needsOverwrite = true;
- $scope.clone.busy = false;
- return;
- }
- if (result.needsOverwrite) {
- $scope.clone.error.location = 'DNS Record already exists. Confirm that the domain is not in use for services external to Cloudron';
- $scope.clone.needsOverwrite = true;
+ if (result.needsOverwrite) {
+ $scope.clone.needsOverwrite = true;
+ $scope.clone.overwriteDns = true;
+ return callback({ type: 'exists', fqdn: fqdn, message: 'DNS Record already exists. Confirm that the domain is not in use for services external to Cloudron' });
+ }
+
+ callback();
+ });
+ }, function (error) {
+ if (error) {
+ if (error.type) {
+ $scope.clone.error.location = error;
+ $scope.clone.busy = false;
+ } else {
+ Client.error(error);
+ }
+
+ $scope.clone.error.location = error;
$scope.clone.busy = false;
return;
}