diff --git a/examples/cluster/server.js b/examples/cluster/server.js index 575b602..03e4eea 100644 --- a/examples/cluster/server.js +++ b/examples/cluster/server.js @@ -14,9 +14,9 @@ require("../../") // Note: in cluster you CANNOT use in-memory state (see below) cluster: true, - // This will default to the number of workers being equal to - // n-1 cpus, with a minimum of 2 - workers: 4 + // This will default to the number of workers being equal to + // n-1 cpus, with a minimum of 2 + workers: 4 }; }) .serve(httpsWorker); diff --git a/examples/http2/server.js b/examples/http2/server.js index 6518b4d..023b3c3 100644 --- a/examples/http2/server.js +++ b/examples/http2/server.js @@ -12,12 +12,12 @@ var pkg = require("../../package.json"); function httpsWorker(glx) { // - // HTTP2 is the default httpsServer for node v12+ - // (HTTPS/1.1 is used for node <= v11) + // HTTP2 would have been the default httpsServer for node v12+ + // However... https://github.com/expressjs/express/issues/3388 // // Get the raw http2 server: - var http2Server = glx.httpsServer(function(req, res) { + var http2Server = glx.http2Server(function(req, res) { res.end("Hello, Encrypted World!"); }); diff --git a/examples/https/server.js b/examples/https/server.js index d4a2c58..ace97bf 100644 --- a/examples/https/server.js +++ b/examples/https/server.js @@ -12,10 +12,9 @@ var pkg = require("../../package.json"); function httpsWorker(glx) { // - // HTTPS/1.1 is only used for node v11 or lower - // (HTTP2 is used for node v12+) + // HTTPS 1.1 is the default + // (HTTP2 would be the default but... https://github.com/expressjs/express/issues/3388) // - // Why not just require('https')? // Get the raw https server: var httpsServer = glx.httpsServer(null, function(req, res) { diff --git a/examples/spdy/server.js b/examples/spdy/server.js index 0e9c26d..2f87b49 100644 --- a/examples/spdy/server.js +++ b/examples/spdy/server.js @@ -1,3 +1,3 @@ // SPDY is dead. It was replaced by HTTP2, which is a native node module // -// Greenlock uses HTTP2 as the default https server in node v12+ +// Check out the http2 example just up one folder diff --git a/main.js b/main.js index 661b672..1e3c309 100644 --- a/main.js +++ b/main.js @@ -8,12 +8,8 @@ var minor = process.versions.node.split(".")[1]; var _hasSetSecureContext = false; var shouldUpgrade = false; -// TODO can we trust earlier versions as well? -if (major >= 12) { - _hasSetSecureContext = !!require("http2").createSecureServer({}, function() {}).setSecureContext; -} else { - _hasSetSecureContext = !!require("https").createServer({}, function() {}).setSecureContext; -} +// this applies to http2 as well (should exist in both or neither) +_hasSetSecureContext = !!require("https").createServer({}, function() {}).setSecureContext; // TODO document in issues if (!_hasSetSecureContext) { diff --git a/package-lock.json b/package-lock.json index 2164bbe..5bc06a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@root/greenlock-express", - "version": "3.0.7", + "version": "3.0.11", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -40,9 +40,9 @@ "integrity": "sha512-OaEub02ufoU038gy6bsNHQOjIn8nUjGiLcaRmJ40IUykneJkIW5fxDqKxQx48cszuNflYldsJLPPXCrGfHs8yQ==" }, "@root/greenlock": { - "version": "3.0.17", - "resolved": "https://registry.npmjs.org/@root/greenlock/-/greenlock-3.0.17.tgz", - "integrity": "sha512-1XKhcLFEx1WFdn1Bc2rkAE/SL1ZUJYYMZdbnehTrfhCr5Y+9U1gdkNZnR/jInhoUvcicF/PXuZkGVucU50RNUg==", + "version": "3.0.25", + "resolved": "https://registry.npmjs.org/@root/greenlock/-/greenlock-3.0.25.tgz", + "integrity": "sha512-VC8H9MTkbqxlB2LGntmcq5cstkE0TdZLvxm25SO5i7c6abJBVMQafhTD415OXwoGimnmWTn6SZ93Fj73d9QX/w==", "requires": { "@root/acme": "^3.0.8", "@root/csr": "^0.8.1", @@ -77,9 +77,9 @@ "integrity": "sha512-rEUDiUsHtild8GfIjFE9wXtcVxeS+ehCJQBwbQQ3IVfORKHK93CFnRtkr69R75lZFjcmKYVc+AXDB+AeRFOULA==" }, "@root/request": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/@root/request/-/request-1.4.1.tgz", - "integrity": "sha512-2zSP1v9VhJ3gvm4oph0C4BYCoM3Sj84/Wx4iKdt0IbqbJzfON04EodBq5dsV65UxO/aHZciUBwY2GCZcHqaTYg==" + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@root/request/-/request-1.4.2.tgz", + "integrity": "sha512-J8FM4+SJuc7WRC+Jz17m+VT2lgI7HtatHhxN1F2ck5aIKUAxJEaR4u/gLBsgT60mVHevKCjKN0O8115UtJjwLw==" }, "@root/x509": { "version": "0.7.2", diff --git a/package.json b/package.json index b1dfd4a..ecf89ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@root/greenlock-express", - "version": "3.0.11", + "version": "3.0.12", "description": "Free SSL and managed or automatic HTTPS for node.js with Express, Koa, Connect, Hapi, and all other middleware systems.", "main": "greenlock-express.js", "homepage": "https://greenlock.domains", @@ -17,7 +17,7 @@ "example": "examples" }, "dependencies": { - "@root/greenlock": "^3.0.17", + "@root/greenlock": "^3.0.25", "redirect-https": "^1.1.5" }, "trulyOptionalDependencies": { diff --git a/servers.js b/servers.js index 9209fcc..fc480e2 100644 --- a/servers.js +++ b/servers.js @@ -31,7 +31,18 @@ Servers.create = function(greenlock) { var _middlewareApp; + servers.http2Server = function(secureOpts, defaultApp) { + return servers._httpsServer(secureOpts, defaultApp, function(secureOpts, fn) { + secureOpts.allowHTTP1 = true; + return require("http2").createSecureServer(secureOpts, fn); + }); + }; servers.httpsServer = function(secureOpts, defaultApp) { + return servers._httpsServer(secureOpts, defaultApp, function(secureOpts, fn) { + return require("https").createServer(secureOpts, fn); + }); + }; + servers._httpsServer = function(secureOpts, defaultApp, createSecureServer) { if (defaultApp) { // TODO guard against being set twice? _middlewareApp = defaultApp; @@ -143,15 +154,3 @@ function wrapDefaultSniCallback(greenlock, secureOpts) { secureOpts.SNICallback = sni.create(greenlock, secureOpts); return secureOpts; } - -function createSecureServer(secureOpts, fn) { - var major = process.versions.node.split(".")[0]; - - // TODO can we trust earlier versions as well? - if (major >= 12) { - secureOpts.allowHTTP1 = true; - return require("http2").createSecureServer(secureOpts, fn); - } else { - return require("https").createServer(secureOpts, fn); - } -}