Move setupDns to cloudron.js

This commit is contained in:
Girish Ramakrishnan
2017-01-12 11:00:46 -08:00
parent 2b49cde2c2
commit d6ea7fc3a0
2 changed files with 22 additions and 5 deletions

View File

@@ -87,13 +87,11 @@ function dnsSetup(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
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, req.body.domain, function (error) {
if (error && error.reason === SettingsError.BAD_FIELD) return next(new HttpError(400, error.message));
cloudron.dnsSetup(req.body, req.body.domain, function (error) {
if (error && error.reason === CloudronError.ALREADY_SETUP) return next(new HttpError(409, error.message));
if (error && error.reason === CloudronError.BAD_FIELD) return next(new HttpError(400, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200));