v3.0.12: from http2 back to old https.. :-/

This commit is contained in:
AJ ONeal 2019-11-01 15:13:04 -06:00
parent 627ad8272e
commit b80537f07b
8 changed files with 31 additions and 37 deletions

View File

@ -12,12 +12,12 @@ var pkg = require("../../package.json");
function httpsWorker(glx) { function httpsWorker(glx) {
// //
// HTTP2 is the default httpsServer for node v12+ // HTTP2 would have been the default httpsServer for node v12+
// (HTTPS/1.1 is used for node <= v11) // However... https://github.com/expressjs/express/issues/3388
// //
// Get the raw http2 server: // Get the raw http2 server:
var http2Server = glx.httpsServer(function(req, res) { var http2Server = glx.http2Server(function(req, res) {
res.end("Hello, Encrypted World!"); res.end("Hello, Encrypted World!");
}); });

View File

@ -12,10 +12,9 @@ var pkg = require("../../package.json");
function httpsWorker(glx) { function httpsWorker(glx) {
// //
// HTTPS/1.1 is only used for node v11 or lower // HTTPS 1.1 is the default
// (HTTP2 is used for node v12+) // (HTTP2 would be the default but... https://github.com/expressjs/express/issues/3388)
// //
// Why not just require('https')?
// Get the raw https server: // Get the raw https server:
var httpsServer = glx.httpsServer(null, function(req, res) { var httpsServer = glx.httpsServer(null, function(req, res) {

View File

@ -1,3 +1,3 @@
// SPDY is dead. It was replaced by HTTP2, which is a native node module // 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

View File

@ -8,12 +8,8 @@ var minor = process.versions.node.split(".")[1];
var _hasSetSecureContext = false; var _hasSetSecureContext = false;
var shouldUpgrade = false; var shouldUpgrade = false;
// TODO can we trust earlier versions as well? // this applies to http2 as well (should exist in both or neither)
if (major >= 12) {
_hasSetSecureContext = !!require("http2").createSecureServer({}, function() {}).setSecureContext;
} else {
_hasSetSecureContext = !!require("https").createServer({}, function() {}).setSecureContext; _hasSetSecureContext = !!require("https").createServer({}, function() {}).setSecureContext;
}
// TODO document in issues // TODO document in issues
if (!_hasSetSecureContext) { if (!_hasSetSecureContext) {

14
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@root/greenlock-express", "name": "@root/greenlock-express",
"version": "3.0.7", "version": "3.0.11",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -40,9 +40,9 @@
"integrity": "sha512-OaEub02ufoU038gy6bsNHQOjIn8nUjGiLcaRmJ40IUykneJkIW5fxDqKxQx48cszuNflYldsJLPPXCrGfHs8yQ==" "integrity": "sha512-OaEub02ufoU038gy6bsNHQOjIn8nUjGiLcaRmJ40IUykneJkIW5fxDqKxQx48cszuNflYldsJLPPXCrGfHs8yQ=="
}, },
"@root/greenlock": { "@root/greenlock": {
"version": "3.0.17", "version": "3.0.25",
"resolved": "https://registry.npmjs.org/@root/greenlock/-/greenlock-3.0.17.tgz", "resolved": "https://registry.npmjs.org/@root/greenlock/-/greenlock-3.0.25.tgz",
"integrity": "sha512-1XKhcLFEx1WFdn1Bc2rkAE/SL1ZUJYYMZdbnehTrfhCr5Y+9U1gdkNZnR/jInhoUvcicF/PXuZkGVucU50RNUg==", "integrity": "sha512-VC8H9MTkbqxlB2LGntmcq5cstkE0TdZLvxm25SO5i7c6abJBVMQafhTD415OXwoGimnmWTn6SZ93Fj73d9QX/w==",
"requires": { "requires": {
"@root/acme": "^3.0.8", "@root/acme": "^3.0.8",
"@root/csr": "^0.8.1", "@root/csr": "^0.8.1",
@ -77,9 +77,9 @@
"integrity": "sha512-rEUDiUsHtild8GfIjFE9wXtcVxeS+ehCJQBwbQQ3IVfORKHK93CFnRtkr69R75lZFjcmKYVc+AXDB+AeRFOULA==" "integrity": "sha512-rEUDiUsHtild8GfIjFE9wXtcVxeS+ehCJQBwbQQ3IVfORKHK93CFnRtkr69R75lZFjcmKYVc+AXDB+AeRFOULA=="
}, },
"@root/request": { "@root/request": {
"version": "1.4.1", "version": "1.4.2",
"resolved": "https://registry.npmjs.org/@root/request/-/request-1.4.1.tgz", "resolved": "https://registry.npmjs.org/@root/request/-/request-1.4.2.tgz",
"integrity": "sha512-2zSP1v9VhJ3gvm4oph0C4BYCoM3Sj84/Wx4iKdt0IbqbJzfON04EodBq5dsV65UxO/aHZciUBwY2GCZcHqaTYg==" "integrity": "sha512-J8FM4+SJuc7WRC+Jz17m+VT2lgI7HtatHhxN1F2ck5aIKUAxJEaR4u/gLBsgT60mVHevKCjKN0O8115UtJjwLw=="
}, },
"@root/x509": { "@root/x509": {
"version": "0.7.2", "version": "0.7.2",

View File

@ -1,6 +1,6 @@
{ {
"name": "@root/greenlock-express", "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.", "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", "main": "greenlock-express.js",
"homepage": "https://greenlock.domains", "homepage": "https://greenlock.domains",
@ -17,7 +17,7 @@
"example": "examples" "example": "examples"
}, },
"dependencies": { "dependencies": {
"@root/greenlock": "^3.0.17", "@root/greenlock": "^3.0.25",
"redirect-https": "^1.1.5" "redirect-https": "^1.1.5"
}, },
"trulyOptionalDependencies": { "trulyOptionalDependencies": {

View File

@ -31,7 +31,18 @@ Servers.create = function(greenlock) {
var _middlewareApp; 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) { 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) { if (defaultApp) {
// TODO guard against being set twice? // TODO guard against being set twice?
_middlewareApp = defaultApp; _middlewareApp = defaultApp;
@ -143,15 +154,3 @@ function wrapDefaultSniCallback(greenlock, secureOpts) {
secureOpts.SNICallback = sni.create(greenlock, secureOpts); secureOpts.SNICallback = sni.create(greenlock, secureOpts);
return 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);
}
}