From 1fec86d3ab0706e085a763d2fc86664588e73d65 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 10 Aug 2016 22:33:12 -0400 Subject: [PATCH] normalize approveDomains --- lib/master.js | 4 ++-- lib/worker.js | 2 +- serve.js | 21 +++++++++++---------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/master.js b/lib/master.js index 5c3c179..08c6dcd 100644 --- a/lib/master.js +++ b/lib/master.js @@ -3,7 +3,7 @@ module.exports.create = function (opts) { if (!opts.letsencrypt) { opts.letsencrypt = require('letsencrypt').create({ server: opts.server }); } if ('function' !== typeof opts.approveDomains) { - throw new Error("You must provide opts.approveDomains(options, certs, callback) to approve certificates"); + throw new Error("You must provide opts.approveDomains(domain, certs, callback) to approve certificates"); } function log(debug) { @@ -30,7 +30,7 @@ module.exports.create = function (opts) { return; } - opts.approveDomains(msg.options, msg.certs, function (err, results) { + opts.approveDomains(msg.domain, msg.certs, function (err, results) { if (err) { log(opts.debug, 'Approval got ERROR', err.stack || err); worker.send({ type: 'LE_RESPONSE', error: err }); diff --git a/lib/worker.js b/lib/worker.js index a62673a..13cf3be 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -5,7 +5,7 @@ module.exports.create = function (opts) { opts.workerSniCallback = require('le-sni-auto').create({ getCertificates: function (domain, certs, cb) { opts.approveDomains(domain, certs, function (err, certs) { - process.send({ type: 'LE_REQUEST', domain: domain, certs: certs }); + process.send({ type: 'LE_REQUEST', domain: domain, options: { domains: [domain] } certs: certs }); process.on('message', function (msg) { if (msg.domain === domain) { diff --git a/serve.js b/serve.js index f306c05..0e2d741 100644 --- a/serve.js +++ b/serve.js @@ -5,7 +5,7 @@ var cluster = require('cluster'); function runMaster() { var numCores = 2; // // Math.max(2, require('os').cpus().length) var i; - var master = require('./master').create({ + var master = require('./lib/master').create({ debug: true @@ -14,14 +14,15 @@ function runMaster() { - , approveDomains: function (options, certs, cb) { + , approveDomains: function (domain, certs, cb) { // Depending on your setup it may be more efficient // for you to implement the approveDomains function // in your master or in your workers. // // Since we implement it in the worker (below) in this example // we'll give it an immediate approval here in the master - cb(null, { options: options, certs: certs }); + var results = { options: { domains: [domain] }, certs: certs }; + cb(null, results); } }); @@ -33,7 +34,7 @@ function runMaster() { } function runWorker() { - var worker = require('./worker').create({ + var worker = require('./lib/worker').create({ debug: true // We want both to renew well before the expiration date @@ -49,9 +50,10 @@ function runWorker() { cb(null, ); } */ - , approveDomains: function (opts, certs, cb) { + , approveDomains: function (domain, certs, cb) { // opts = { domains, email, agreeTos, tosUrl } // certs = { subject, altnames, expiresAt, issuedAt } + var results = { options: { domains: [domain] }, certs: certs }; @@ -61,7 +63,7 @@ function runWorker() { // for renewals to be automatic if (certs) { // modify opts.domains to overwrite certs.altnames in renewal - cb(null, { options: opts, certs: certs }); + cb(null, results); return; } @@ -71,8 +73,7 @@ function runWorker() { // This is where we would check our database to make sure that // this user (specified by email address) has agreed to the terms // and do some check that they have access to this domain - opts.agreeTos = true; - cb(null, { options: opts }); + cb(null, results); } }); @@ -80,8 +81,8 @@ function runWorker() { res.end("Hello, World!"); } - var plainServer = require('http').createServer(worker.handleAcmeAndRedirectToHttps); - var server = require('https').createServer(worker.httpsOptions, worker.handleAcmeAndUse(app)); + var plainServer = require('http').createServer(worker.handleAcmeOrRedirectToHttps()); + var server = require('https').createServer(worker.httpsOptions, worker.handleAcmeOrUse(app)); plainServer.listen(80); server.listen(443); }