Skip to content

Commit

Permalink
fix: add workaround for Origin header in sockjs
Browse files Browse the repository at this point in the history
  • Loading branch information
timfjord committed Mar 13, 2019
1 parent f6c6af6 commit ff8b19c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ const webpackDevMiddleware = require('webpack-dev-middleware');
const OptionsValidationError = require('./OptionsValidationError');
const optionsSchema = require('./optionsSchema.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
{
// 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;
}
};
}

const clientStats = { errorDetails: false };
const log = console.log; // eslint-disable-line no-console

Expand Down

0 comments on commit ff8b19c

Please sign in to comment.