From 06c5a6f859a0cf4442bcf1672ebc55bc28547ef8 Mon Sep 17 00:00:00 2001 From: 3846masa <3846masahiro+git@gmail.com> Date: Sun, 23 Dec 2018 03:25:30 +0900 Subject: [PATCH 1/2] Add workaround for sockjs@~0.13.9 sockjs will remove Origin header, however Origin header is required for checking host. This workaround maybe broken at sockjs@^0.14.x because of refactoring. --- lib/Server.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/Server.js b/lib/Server.js index 90494c99b1..f1aaef0537 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -43,6 +43,21 @@ const createCertificate = require('./utils/createCertificate'); const validateOptions = require('schema-utils'); const schema = require('./options.json'); +// Workaround for sockjs@~0.3.19 +// sockjs will remove Origin header, however Origin header is required for checking host. +// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information +{ + const SockjsSession = require('sockjs/lib/transport').Session; + const decorateConnection = SockjsSession.prototype.decorateConnection; + SockjsSession.prototype.decorateConnection = function(req) { + decorateConnection.call(this, req); + const connection = this.connection; + if (connection.headers && !('origin' in connection.headers) && 'origin' in req.headers) { + connection.headers['origin'] = req.headers['origin']; + } + }; +} + // Workaround for node ^8.6.0, ^9.0.0 // DEFAULT_ECDH_CURVE is default to prime256v1 in these version // breaking connection when certificate is not signed with prime256v1 From e749b6a4dd5b96a1aedd5c9f08b2ba250bcc337c Mon Sep 17 00:00:00 2001 From: 3846masa <3846masahiro+git@gmail.com> Date: Sun, 23 Dec 2018 03:47:43 +0900 Subject: [PATCH 2/2] Fix code style --- lib/Server.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Server.js b/lib/Server.js index f1aaef0537..6e7cb21e8a 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -47,13 +47,14 @@ const schema = require('./options.json'); // sockjs will remove Origin header, however Origin header is required for checking host. // See https://github.com/webpack/webpack-dev-server/issues/1604 for more information { + // eslint-disable-next-line global-require const SockjsSession = require('sockjs/lib/transport').Session; const decorateConnection = SockjsSession.prototype.decorateConnection; SockjsSession.prototype.decorateConnection = function(req) { decorateConnection.call(this, req); const connection = this.connection; if (connection.headers && !('origin' in connection.headers) && 'origin' in req.headers) { - connection.headers['origin'] = req.headers['origin']; + connection.headers.origin = req.headers.origin; } }; }