Skip to content

Commit

Permalink
fix(server): revert "union sock options (#2047)" (#2261)
Browse files Browse the repository at this point in the history
  • Loading branch information
EslamHiko committed Sep 25, 2019
1 parent fe80fa4 commit adc1154
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 76 deletions.
8 changes: 2 additions & 6 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,10 @@ class Server {
this.hot = this.options.hot || this.options.hotOnly;
this.watchOptions = options.watchOptions || {};

if (!this.options.clientSocketOptions) {
this.options.clientSocketOptions = {};
}

// Replace leading and trailing slashes to normalize path
this.sockPath = `/${
this.options.clientSocketOptions.path
? this.options.clientSocketOptions.path.replace(/^\/|\/$/g, '')
this.options.sockPath
? this.options.sockPath.replace(/^\/|\/$/g, '')
: 'sockjs-node'
}`;

Expand Down
44 changes: 22 additions & 22 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,6 @@
"clientLogLevel": {
"enum": ["info", "warn", "error", "debug", "trace", "silent"]
},
"clientSocketOptions": {
"type": "object",
"properties": {
"host": {
"type": "string"
},
"path": {
"type": "string"
},
"port": {
"anyOf": [
{
"type": "string"
},
{
"type": "number"
}
]
}
}
},
"compress": {
"type": "boolean"
},
Expand Down Expand Up @@ -318,6 +297,25 @@
"setup": {
"instanceof": "Function"
},
"sockHost": {
"type": "string"
},
"sockPath": {
"type": "string"
},
"sockPort": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
},
{
"type": "null"
}
]
},
"socket": {
"type": "string"
},
Expand Down Expand Up @@ -405,7 +403,6 @@
"ca": "should be {String|Buffer}",
"cert": "should be {String|Buffer}",
"clientLogLevel": "should be {String} and equal to one of the allowed values\n\n [ 'silent', 'info', 'debug', 'trace', 'error', 'warn' ]\n\n (https://webpack.js.org/configuration/dev-server/#devserverclientloglevel)",
"clientSocketOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverclientsocketoptions)",
"compress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devservercompress)",
"contentBase": "should be {Number|String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbase)",
"disableHostCheck": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck)",
Expand Down Expand Up @@ -449,6 +446,9 @@
"serveIndex": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverserveindex)",
"serverSideRender": "should be {Boolean} (https://github.com/webpack/webpack-dev-middleware#serversiderender)",
"setup": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserversetup)",
"sockHost": "should be {String|Null} (https://webpack.js.org/configuration/dev-server/#devserversockhost)",
"sockPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserversockpath)",
"sockPort": "should be {Number|String|Null} (https://webpack.js.org/configuration/dev-server/#devserversockport)",
"socket": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserversocket)",
"staticOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverstaticoptions)",
"stats": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserverstats-)",
Expand Down
10 changes: 3 additions & 7 deletions lib/utils/addEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ function addEntries(config, options, server) {
},
};

if (!options.clientSocketOptions) {
options.clientSocketOptions = {};
}

/** @type {string} */
const domain = createDomain(options, app);
/** @type {string} */
const sockHost = options.clientSocketOptions.host ? `&sockHost=${options.clientSocketOptions.host}` : '';
const sockHost = options.sockHost ? `&sockHost=${options.sockHost}` : '';
/** @type {string} */
const sockPath = options.clientSocketOptions.path ? `&sockPath=${options.clientSocketOptions.path}` : '';
const sockPath = options.sockPath ? `&sockPath=${options.sockPath}` : '';
/** @type {string} */
const sockPort = options.clientSocketOptions.port ? `&sockPort=${options.clientSocketOptions.port}` : '';
const sockPort = options.sockPort ? `&sockPort=${options.sockPort}` : '';
/** @type {string} */
const clientEntry = `${require.resolve(
'../../client/'
Expand Down
13 changes: 3 additions & 10 deletions lib/utils/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,16 @@ function createConfig(config, argv, { port }) {
options.socket = argv.socket;
}

if (
(argv.sockHost || argv.sockPath || argv.sockPort) &&
!options.clientSocketOptions
) {
options.clientSocketOptions = {};
}

if (argv.sockHost) {
options.clientSocketOptions.host = argv.sockHost;
options.sockHost = argv.sockHost;
}

if (argv.sockPath) {
options.clientSocketOptions.path = argv.sockPath;
options.sockPath = argv.sockPath;
}

if (argv.sockPort) {
options.clientSocketOptions.port = argv.sockPort;
options.sockPort = argv.sockPort;
}

if (argv.liveReload === false) {
Expand Down
18 changes: 5 additions & 13 deletions test/e2e/ClientOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ describe('Client complex inline script path', () => {
poll: true,
},
public: 'myhost.test',
clientSocketOptions: {
path: '/foo/test/bar/',
},
sockPath: '/foo/test/bar/',
quiet: true,
};
testServer.startAwaitingCompilation(config, options, done);
Expand Down Expand Up @@ -140,10 +138,8 @@ describe('Client complex inline script path with sockPort', () => {
watchOptions: {
poll: true,
},
clientSocketOptions: {
path: '/foo/test/bar/',
port: port3,
},
sockPath: '/foo/test/bar/',
sockPort: port3,
quiet: true,
};
testServer.startAwaitingCompilation(config, options, done);
Expand Down Expand Up @@ -189,9 +185,7 @@ describe('Client complex inline script path with sockPort, no sockPath', () => {
watchOptions: {
poll: true,
},
clientSocketOptions: {
port: port3,
},
sockPort: port3,
quiet: true,
};
testServer.startAwaitingCompilation(config, options, done);
Expand Down Expand Up @@ -231,9 +225,7 @@ describe('Client complex inline script path with sockHost', () => {
watchOptions: {
poll: true,
},
clientSocketOptions: {
host: 'myhost.test',
},
sockHost: 'myhost.test',
quiet: true,
};
testServer.startAwaitingCompilation(config, options, done);
Expand Down
12 changes: 10 additions & 2 deletions test/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,16 @@ describe('options', () => {
success: [''],
failure: [false],
},
clientSocketOptions: {
success: [{}],
sockHost: {
success: [''],
failure: [false],
},
sockPath: {
success: [''],
failure: [false],
},
sockPort: {
success: ['', 0, null],
failure: [false],
},
staticOptions: {
Expand Down
4 changes: 1 addition & 3 deletions test/server/sockPath-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ describe('sockPath options', () => {
server = testServer.start(
config,
{
clientSocketOptions: {
path: '/foo/test/bar/',
},
sockPath: '/foo/test/bar/',
port,
},
done
Expand Down
6 changes: 2 additions & 4 deletions test/server/transportMode-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ describe('transportMode', () => {
config,
{
port,
clientSocketOptions: {
path: '/foo/test/bar/',
},
sockPath: '/foo/test/bar/',
transportMode: {
server: class MySockJSServer extends BaseServer {
constructor(serv) {
Expand All @@ -219,7 +217,7 @@ describe('transportMode', () => {
prefix: this.server.sockPath,
});

sockPath = server.options.clientSocketOptions.path;
sockPath = server.options.sockPath;
}

send(connection, message) {
Expand Down
12 changes: 3 additions & 9 deletions test/server/utils/__snapshots__/createConfig.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1202,14 +1202,12 @@ Object {

exports[`createConfig sockHost option 1`] = `
Object {
"clientSocketOptions": Object {
"host": true,
},
"hot": true,
"hotOnly": false,
"noInfo": true,
"port": 8080,
"publicPath": "/",
"sockHost": true,
"stats": Object {
"cached": false,
"cachedAssets": false,
Expand All @@ -1219,14 +1217,12 @@ Object {

exports[`createConfig sockPath option 1`] = `
Object {
"clientSocketOptions": Object {
"path": "path",
},
"hot": true,
"hotOnly": false,
"noInfo": true,
"port": 8080,
"publicPath": "/",
"sockPath": "path",
"stats": Object {
"cached": false,
"cachedAssets": false,
Expand All @@ -1236,14 +1232,12 @@ Object {

exports[`createConfig sockPort option 1`] = `
Object {
"clientSocketOptions": Object {
"port": "port",
},
"hot": true,
"hotOnly": false,
"noInfo": true,
"port": 8080,
"publicPath": "/",
"sockPort": "port",
"stats": Object {
"cached": false,
"cachedAssets": false,
Expand Down

0 comments on commit adc1154

Please sign in to comment.