Skip to content

Commit f4672e2

Browse files
author
Rohan Bhanderi
committed
Fix server: don't use spdy on node >= v10.0.0
Ports fix for webpack#1449 to v2 branch cherry pick of webpack@e97d345 this issue was fixed in webpack-dev-server v3 line, which requires webpack to be upgraded to >= 4.0.0. This commit cherry picks the fix to v2 branch (on top of v2.11.3) which does not require webpack to be upgraded to 4.0.0 `spdy` is effectively unmaintained, and as a consequence of an implementation that extensively relies on Node’s non-public APIs, broken on Node 10 and above. In those cases, only https will be used for now. Once express supports Node's built-in HTTP/2 support, migrating over to that should be the best way to go. related issues: nodejs/node#21665 nodejs/node#21665 webpack#1449 expressjs/express#3388
1 parent 1d2adbd commit f4672e2

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/Server.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const serveIndex = require('serve-index');
1818
const historyApiFallback = require('connect-history-api-fallback');
1919
const selfsigned = require('selfsigned');
2020
const sockjs = require('sockjs');
21+
const https = require('https');
2122
const spdy = require('spdy');
2223
const webpack = require('webpack');
2324
const webpackDevMiddleware = require('webpack-dev-middleware');
@@ -481,7 +482,20 @@ function Server(compiler, options) {
481482
};
482483
}
483484

484-
this.listeningApp = spdy.createServer(options.https, app);
485+
// `spdy` is effectively unmaintained, and as a consequence of an
486+
// implementation that extensively relies on Node’s non-public APIs, broken
487+
// on Node 10 and above. In those cases, only https will be used for now.
488+
// Once express supports Node's built-in HTTP/2 support, migrating over to
489+
// that should be the best way to go.
490+
// The relevant issues are:
491+
// - https://github.com/nodejs/node/issues/21665
492+
// - https://github.com/webpack/webpack-dev-server/issues/1449
493+
// - https://github.com/expressjs/express/issues/3388
494+
if (+process.version.match(/^v(\d+)/)[1] >= 10) {
495+
this.listeningApp = https.createServer(options.https, app);
496+
} else {
497+
this.listeningApp = spdy.createServer(options.https, app);
498+
}
485499
} else {
486500
this.listeningApp = http.createServer(app);
487501
}

test/Https.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const path = require('path');
3+
const request = require('supertest');
4+
const helper = require('./helper');
5+
const config = require('./fixtures/contentbase-config/webpack.config');
6+
require('mocha-sinon');
7+
const contentBasePublic = path.join(__dirname, 'fixtures/contentbase-config/public');
8+
describe('HTTPS', function testHttps() {
9+
let server;
10+
let req;
11+
afterEach(helper.close);
12+
// Increase the timeout to 20 seconds to allow time for key generation.
13+
this.timeout(20000);
14+
describe('to directory', () => {
15+
before((done) => {
16+
server = helper.start(config, {
17+
contentBase: contentBasePublic,
18+
https: true
19+
}, done);
20+
req = request(server.app);
21+
});
22+
it('Request to index', (done) => {
23+
req.get('/')
24+
.expect(200, /Heyo/, done);
25+
});
26+
});
27+
});

0 commit comments

Comments
 (0)