diff --git a/src/domains.js b/src/domains.js index d1697c32f..c66f530d5 100644 --- a/src/domains.js +++ b/src/domains.js @@ -8,6 +8,8 @@ module.exports = exports = { del: del, isLocked: isLocked, + renewCerts: renewCerts, + fqdn: fqdn, setAdmin: setAdmin, @@ -487,3 +489,16 @@ function makeWildcard(hostname) { parts[0] = '*'; return parts.join('.'); } + +function renewCerts(domain, auditSource, callback) { + assert.strictEqual(typeof domain, 'string'); + assert.strictEqual(typeof auditSource, 'object'); + assert.strictEqual(typeof callback, 'function'); + + // trigger renewal in the background + reverseProxy.renewCerts({ domain: domain }, auditSource, function (error) { + debug('renewCerts', error); + }); + + callback(); +} diff --git a/src/routes/domains.js b/src/routes/domains.js index 8ddd99602..38ee62eb1 100644 --- a/src/routes/domains.js +++ b/src/routes/domains.js @@ -16,8 +16,7 @@ var assert = require('assert'), domains = require('../domains.js'), DomainsError = domains.DomainsError, HttpError = require('connect-lastmile').HttpError, - HttpSuccess = require('connect-lastmile').HttpSuccess, - reverseProxy = require('../reverseproxy.js'); + HttpSuccess = require('connect-lastmile').HttpSuccess; function auditSource(req) { var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || null; @@ -134,8 +133,12 @@ function del(req, res, next) { function renewCerts(req, res, next) { assert.strictEqual(typeof req.params.domain, 'string'); - // trigger renewal in the background - reverseProxy.renewCerts({ domain: req.params.domain }, auditSource(req), function () { }); + domains.renewCerts(req.params.domain, auditSource(req), function (error) { + if (error && error.reason === DomainsError.NOT_FOUND) return next(new HttpError(404, error.message)); + if (error) return next(new HttpError(500, error)); + + next(new HttpSuccess(202, {})); + }); next(new HttpSuccess(202, {})); }