Skip to content

Commit ff8b19c

Browse files
committed
fix: add workaround for Origin header in sockjs
1 parent f6c6af6 commit ff8b19c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/Server.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ const webpackDevMiddleware = require('webpack-dev-middleware');
2424
const OptionsValidationError = require('./OptionsValidationError');
2525
const optionsSchema = require('./optionsSchema.json');
2626

27+
// Workaround for sockjs@~0.3.19
28+
// sockjs will remove Origin header, however Origin header is required for checking host.
29+
// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
30+
{
31+
// eslint-disable-next-line global-require
32+
const SockjsSession = require('sockjs/lib/transport').Session;
33+
const decorateConnection = SockjsSession.prototype.decorateConnection;
34+
SockjsSession.prototype.decorateConnection = function(req) {
35+
decorateConnection.call(this, req);
36+
const connection = this.connection;
37+
if (connection.headers && !('origin' in connection.headers) && 'origin' in req.headers) {
38+
connection.headers.origin = req.headers.origin;
39+
}
40+
};
41+
}
42+
2743
const clientStats = { errorDetails: false };
2844
const log = console.log; // eslint-disable-line no-console
2945

0 commit comments

Comments
 (0)