greenlock-express.js/greenlock-shim.js

71 lines
2.0 KiB
JavaScript
Raw Normal View History

2019-10-27 09:59:49 +00:00
"use strict";
module.exports.create = function(opts) {
2019-11-01 21:14:07 +00:00
var Greenlock = require("@root/greenlock");
2019-11-19 08:19:27 +00:00
//var Init = require("@root/greenlock/lib/init.js");
2019-11-05 10:09:42 +00:00
var greenlock = opts.greenlock;
2019-11-12 08:46:47 +00:00
2019-11-16 23:50:12 +00:00
/*
2019-11-12 08:46:47 +00:00
if (!greenlock && opts.packageRoot) {
try {
greenlock = require(path.resolve(opts.packageRoot, "greenlock.js"));
} catch (e) {
if ("MODULE_NOT_FOUND" !== e.code) {
throw e;
}
}
}
2019-11-16 23:50:12 +00:00
*/
2019-11-05 10:09:42 +00:00
if (!greenlock) {
2019-11-19 08:19:27 +00:00
//opts = Init._init(opts);
2019-11-16 23:50:12 +00:00
greenlock = Greenlock.create(opts);
}
2019-11-18 07:53:26 +00:00
opts.packageAgent = addGreenlockAgent(opts);
2019-11-12 08:46:47 +00:00
2019-11-16 23:50:12 +00:00
try {
if (opts.notify) {
greenlock._defaults.notify = opts.notify;
2019-11-05 10:09:42 +00:00
}
2019-11-16 23:50:12 +00:00
} catch (e) {
console.error("Developer Error: notify not attached correctly");
2019-11-05 10:09:42 +00:00
}
2019-10-28 07:06:43 +00:00
2019-11-01 21:14:07 +00:00
// re-export as top-level function to simplify rpc with workers
greenlock.getAcmeHttp01ChallengeResponse = function(opts) {
return greenlock.challenges.get(opts);
};
2019-10-27 09:59:49 +00:00
2019-11-05 11:01:58 +00:00
greenlock._find({}).then(function(sites) {
if (sites.length <= 0) {
console.warn("warning: No sites available. Did you add them?");
console.warn(" npx greenlock add --subject example.com --altnames example.com");
return;
}
console.info("Ready to Serve:");
2019-11-12 08:46:47 +00:00
2019-11-05 11:01:58 +00:00
var max = 3;
if (sites.length >= 1) {
sites.slice(0, max).forEach(function(site) {
console.info("\t", site.altnames.join(" "));
});
}
if (sites.length > max) {
console.info("and %d others", sites.length - max);
}
});
2019-11-01 21:14:07 +00:00
return greenlock;
2019-10-27 09:59:49 +00:00
};
2019-11-18 07:53:26 +00:00
function addGreenlockAgent(opts) {
// Add greenlock as part of Agent, unless this is greenlock
var packageAgent = opts.packageAgent || "";
if (!/greenlock(-express|-pro)?/i.test(packageAgent)) {
var pkg = require("./package.json");
packageAgent += " Greenlock_Express/" + pkg.version;
}
return packageAgent.trim();
}