reverseproxy: async'ify
This commit is contained in:
42
src/apps.js
42
src/apps.js
@@ -1137,35 +1137,28 @@ function setAutomaticUpdate(app, enable, auditSource, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function setReverseProxyConfig(app, reverseProxyConfig, auditSource, callback) {
|
||||
async function setReverseProxyConfig(app, reverseProxyConfig, auditSource) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof reverseProxyConfig, 'object');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
reverseProxyConfig = _.extend({ robotsTxt: null, csp: null }, reverseProxyConfig);
|
||||
|
||||
const appId = app.id;
|
||||
let error = validateCsp(reverseProxyConfig.csp);
|
||||
if (error) return callback(error);
|
||||
if (error) throw error;
|
||||
|
||||
error = validateRobotsTxt(reverseProxyConfig.robotsTxt);
|
||||
if (error) return callback(error);
|
||||
if (error) throw error;
|
||||
|
||||
reverseProxy.writeAppConfig(_.extend({}, app, { reverseProxyConfig }), function (error) {
|
||||
if (error) return callback(error);
|
||||
await reverseProxy.writeAppConfig(_.extend({}, app, { reverseProxyConfig }));
|
||||
|
||||
appdb.update(appId, { reverseProxyConfig }, function (error) {
|
||||
if (error) return callback(error);
|
||||
await util.promisify(appdb.update)(appId, { reverseProxyConfig });
|
||||
|
||||
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId, app, reverseProxyConfig });
|
||||
|
||||
callback();
|
||||
});
|
||||
});
|
||||
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId, app, reverseProxyConfig });
|
||||
}
|
||||
|
||||
function setCertificate(app, data, auditSource, callback) {
|
||||
async function setCertificate(app, data, auditSource) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert(data && typeof data === 'object');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
@@ -1174,22 +1167,15 @@ function setCertificate(app, data, auditSource, callback) {
|
||||
const appId = app.id;
|
||||
const { location, domain, cert, key } = data;
|
||||
|
||||
domains.get(domain, function (error, domainObject) {
|
||||
if (error) return callback(error);
|
||||
const domainObject = await domains.get(domain);
|
||||
|
||||
if (cert && key) {
|
||||
error = reverseProxy.validateCertificate(location, domainObject, { cert, key });
|
||||
if (error) return callback(error);
|
||||
}
|
||||
if (cert && key) {
|
||||
const error = reverseProxy.validateCertificate(location, domainObject, { cert, key });
|
||||
if (error) throw error;
|
||||
}
|
||||
|
||||
reverseProxy.setAppCertificateSync(location, domainObject, { cert, key }, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId, app, cert, key });
|
||||
|
||||
callback();
|
||||
});
|
||||
});
|
||||
await reverseProxy.setAppCertificateSync(location, domainObject, { cert, key });
|
||||
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId, app, cert, key });
|
||||
}
|
||||
|
||||
function setLocation(app, data, auditSource, callback) {
|
||||
|
||||
Reference in New Issue
Block a user