fix maintainerEmail and httpsServer() return

This commit is contained in:
AJ ONeal 2019-10-31 05:52:30 -06:00
parent 18b36d7d23
commit d324179cb1
2 changed files with 22 additions and 5 deletions

View File

@ -68,12 +68,16 @@ function addGreenlockAgent(opts) {
return packageAgent.trim();
}
// ex: John Doe <john@example.com> (https://john.doe)
var looseEmailRe = /.*([^'" <>:;`]+@[^'" <>:;`]+\.[^'" <>:;`]+).*/;
// ex: "John Doe <john@example.com> (https://john.doe)"
// ex: "John Doe <john@example.com>"
// ex: "<john@example.com>"
// ex: "john@example.com"
var looseEmailRe = /(^|[\s<])([^'" <>:;`]+@[^'" <>:;`]+\.[^'" <>:;`]+)/;
function parsePackage(opts) {
// 'package' is sometimes a reserved word
var pkg = opts.package || opts.pkg;
if (!pkg) {
opts.maintainerEmail = parseMaintainer(opts.maintainerEmail);
return opts;
}
@ -90,13 +94,26 @@ function parsePackage(opts) {
if (!opts.maintainerEmail) {
try {
opts.maintainerEmail = pkg.author.email || pkg.author.match(looseEmailRe)[1];
opts.maintainerEmail = pkg.author.email || pkg.author.match(looseEmailRe)[2];
} catch (e) {}
}
if (!opts.maintainerEmail) {
throw new Error("missing or malformed `package.author`, which is used as the contact for support notices");
}
opts.package = undefined;
opts.maintainerEmail = parseMaintainer(opts.maintainerEmail);
return opts;
}
function parseMaintainer(maintainerEmail) {
try {
maintainerEmail = maintainerEmail.match(looseEmailRe)[2];
} catch (e) {
maintainerEmail = null;
}
if (!maintainerEmail) {
throw new Error("missing or malformed `maintainerEmail`, which is used as the contact for support notices");
}
return maintainerEmail;
}

View File

@ -38,7 +38,7 @@ Servers.create = function(greenlock) {
}
if (_httpsServer) {
if (secureOpts && Object.keys(secureOpts)) {
if (secureOpts && Object.keys(secureOpts).length) {
throw new Error("Call glx.httpsServer(tlsOptions) before calling glx.serveApp(app)");
}
return _httpsServer;
@ -86,7 +86,7 @@ Servers.create = function(greenlock) {
// TODO fetch greenlock.servername
_middlewareApp = app || _middlewareApp;
var secureServer = servers.httpsServer({}, app);
var secureServer = servers.httpsServer(null, app);
var secureAddr = "0.0.0.0";
var securePort = 443;
secureServer.listen(securePort, secureAddr, function() {