diff --git a/src/apps.js b/src/apps.js index cb99206d1..600ac3a5f 100644 --- a/src/apps.js +++ b/src/apps.js @@ -65,6 +65,7 @@ exports = module.exports = { appendLogLine, getCertificate, + getLocationsSync, start, stop, @@ -2862,3 +2863,14 @@ async function restoreConfig(app) { await update(app.id, data); } + +function getLocationsSync(app) { + assert.strictEqual(typeof app, 'object'); + + const locations = [{ domain: app.domain, fqdn: app.fqdn, certificate: app.certificate, type: exports.LOCATION_TYPE_PRIMARY }] + .concat(app.secondaryDomains.map(sd => { return { domain: sd.domain, certificate: sd.certificate, fqdn: sd.fqdn, type: exports.LOCATION_TYPE_SECONDARY }; })) + .concat(app.redirectDomains.map(rd => { return { domain: rd.domain, certificate: rd.certificate, fqdn: rd.fqdn, type: exports.LOCATION_TYPE_REDIRECT }; })) + .concat(app.aliasDomains.map(ad => { return { domain: ad.domain, certificate: ad.certificate, fqdn: ad.fqdn, type: exports.LOCATION_TYPE_ALIAS }; })); + + return locations; +} diff --git a/src/reverseproxy.js b/src/reverseproxy.js index a963f9ef3..8ada33e6b 100644 --- a/src/reverseproxy.js +++ b/src/reverseproxy.js @@ -574,7 +574,7 @@ async function writeAppNginxConfig(app, fqdn, type, certificatePath) { async function writeAppConfigs(app) { assert.strictEqual(typeof app, 'object'); - const locations = appLocationsSync(app); + const locations = apps.getLocationsSync(app); for (const location of locations) { const certificatePath = await getCertificatePath(location.fqdn, location.domain); @@ -602,22 +602,11 @@ async function setUserCertificate(app, fqdn, certificate) { await writeAppConfigs(app); } -function appLocationsSync(app) { - assert.strictEqual(typeof app, 'object'); - - const locations = [{ domain: app.domain, fqdn: app.fqdn, certificate: app.certificate, type: apps.LOCATION_TYPE_PRIMARY }] - .concat(app.secondaryDomains.map(sd => { return { domain: sd.domain, certificate: sd.certificate, fqdn: sd.fqdn, type: apps.LOCATION_TYPE_SECONDARY }; })) - .concat(app.redirectDomains.map(rd => { return { domain: rd.domain, certificate: rd.certificate, fqdn: rd.fqdn, type: apps.LOCATION_TYPE_REDIRECT }; })) - .concat(app.aliasDomains.map(ad => { return { domain: ad.domain, certificate: ad.certificate, fqdn: ad.fqdn, type: apps.LOCATION_TYPE_ALIAS }; })); - - return locations; -} - async function configureApp(app, auditSource) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof auditSource, 'object'); - const locations = await appLocationsSync(app); + const locations = await apps.getLocationsSync(app); const domainObjectMap = await domains.getDomainObjectMap(); for (const location of locations) { @@ -658,7 +647,7 @@ async function renewCerts(auditSource, progressCallback) { for (const app of allApps) { if (app.runState === apps.RSTATE_STOPPED) continue; // do not renew certs of stopped apps - locations = locations.concat(appLocationsSync(app)); + locations = locations.concat(apps.apps.getLocationsSync(app)); } let percent = 1, renewedCertificateNames = []; @@ -706,7 +695,7 @@ async function cleanupCerts(auditSource, progressCallback) { for (const app of await apps.list()) { if (app.runState === apps.RSTATE_STOPPED) continue; // not in use - locations = locations.concat(appLocationsSync(app)); + locations = locations.concat(apps.apps.getLocationsSync(app)); } const certsInUse = [ 'default.cert' ];