Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Union sock options #2047

Merged
merged 3 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ 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.sockPath
? this.options.sockPath.replace(/^\/|\/$/g, '')
this.options.clientSocketOptions.path
? this.options.clientSocketOptions.path.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,6 +39,27 @@
"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 @@ -297,25 +318,6 @@
"setup": {
"instanceof": "Function"
},
"sockHost": {
"type": "string"
},
"sockPath": {
"type": "string"
},
"sockPort": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
},
{
"type": "null"
}
]
},
"socket": {
"type": "string"
},
Expand Down Expand Up @@ -403,6 +405,7 @@
"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 @@ -446,9 +449,6 @@
"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: 7 additions & 3 deletions lib/utils/addEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ function addEntries(config, options, server) {
},
};

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

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

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

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

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

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

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

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

send(connection, message) {
Expand Down
12 changes: 9 additions & 3 deletions test/server/utils/__snapshots__/createConfig.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1202,12 +1202,14 @@ 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 @@ -1217,12 +1219,14 @@ 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 @@ -1232,12 +1236,14 @@ 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