normalize approveDomains

This commit is contained in:
AJ ONeal 2016-08-10 22:33:12 -04:00
förälder 23f7d14087
incheckning 1fec86d3ab
3 ändrade filer med 14 tillägg och 13 borttagningar

Visa fil

@ -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 });

Visa fil

@ -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) {

Visa fil

@ -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);
}