refactor code to allow admin domain to be set

This commit is contained in:
Girish Ramakrishnan
2018-12-07 16:15:21 -08:00
parent 3aea1f3c9d
commit 515ee891d3
5 changed files with 45 additions and 47 deletions

View File

@@ -12,6 +12,7 @@ exports = module.exports = {
getLogs: getLogs,
getLogStream: getLogStream,
getStatus: getStatus,
setAdmin: setAdmin
};
var appstore = require('../appstore.js'),
@@ -173,6 +174,17 @@ function getLogStream(req, res, next) {
});
}
function setAdmin(req, res, next) {
if (!req.body.domain || typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
cloudron.setAdmin(req.body.domain, function (error) {
if (error && error.reason === CloudronError.BAD_FIELD) return next(new HttpError(404, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, status));
});
}
function getStatus(req, res, next) {
cloudron.getStatus(function (error, status) {
if (error) return next(new HttpError(500, error));