diff --git a/greenlock.js b/greenlock.js index b895eb4..21f391b 100644 --- a/greenlock.js +++ b/greenlock.js @@ -68,12 +68,16 @@ function addGreenlockAgent(opts) { return packageAgent.trim(); } -// ex: John Doe (https://john.doe) -var looseEmailRe = /.*([^'" <>:;`]+@[^'" <>:;`]+\.[^'" <>:;`]+).*/; +// ex: "John Doe (https://john.doe)" +// ex: "John Doe " +// ex: "" +// 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; +} diff --git a/servers.js b/servers.js index b1ecb6a..9209fcc 100644 --- a/servers.js +++ b/servers.js @@ -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() {