From be254c087ffb0de819ff688014aa260224609d39 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 12 Dec 2015 15:50:00 +0000 Subject: [PATCH] needRegistration callback --- index.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 20bfdd7..c18c49c 100644 --- a/index.js +++ b/index.js @@ -50,6 +50,10 @@ module.exports.create = function (letsencrypt, defaults, options) { return copy; } + function isCurrent(cache) { + return cache; + } + function sniCallback(hostname, cb) { var args = merge({}); args.domains = [hostname]; @@ -59,15 +63,26 @@ module.exports.create = function (letsencrypt, defaults, options) { return; } - if (!cache.context) { - cache.context = tls.createSecureContext({ - key: cache.key // privkey.pem - , cert: cache.cert // fullchain.pem - //, ciphers // node's defaults are great - }); + function respond(c2) { + cache = c2 || cache; + + if (!cache.context) { + cache.context = tls.createSecureContext({ + key: cache.key // privkey.pem + , cert: cache.cert // fullchain.pem + //, ciphers // node's defaults are great + }); + } + + cb(null, cache.context); } - - cb(null, cache.context); + + if (isCurrent(cache)) { + respond(); + return; + } + + defaults.needsRegistration(hostname, respond); }); }