diff --git a/.gitignore b/.gitignore index efa0cc7443..247cd60e51 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ client coverage ssl/*.pem node_modules +.vscode \ No newline at end of file diff --git a/client-src/default/index.js b/client-src/default/index.js index e0ec3ca10b..8a2d8e1e25 100644 --- a/client-src/default/index.js +++ b/client-src/default/index.js @@ -221,12 +221,14 @@ if ( ) { protocol = self.location.protocol; } - const socketUrl = url.format({ protocol, auth: urlParts.auth, hostname, - port, + port: + urlParts.path == null || urlParts.path === '/' + ? port + : querystring.parse(urlParts.path).sockPort || port, // If sockPath is provided it'll be passed in via the __resourceQuery as a // query param so it has to be parsed out of the querystring in order for the // client to open the socket to the correct location. diff --git a/lib/options.json b/lib/options.json index 80ff4fc952..e77b6edf06 100644 --- a/lib/options.json +++ b/lib/options.json @@ -67,6 +67,19 @@ "sockPath": { "type": "string" }, + "sockPort": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "string" + }, + { + "type": "null" + } + ] + }, "watchOptions": { "type": "object" }, diff --git a/lib/utils/addEntries.js b/lib/utils/addEntries.js index a4d28d9830..b126ee18b7 100644 --- a/lib/utils/addEntries.js +++ b/lib/utils/addEntries.js @@ -17,10 +17,10 @@ function addEntries(config, options, server) { const domain = createDomain(options, app); const sockPath = options.sockPath ? `&sockPath=${options.sockPath}` : ''; + const sockPort = options.sockPort ? `&sockPort=${options.sockPort}` : ''; const entries = [ - `${require.resolve('../../client/')}?${domain}${sockPath}`, + `${require.resolve('../../client/')}?${domain}${sockPath}${sockPort}`, ]; - if (options.hotOnly) { entries.push(require.resolve('webpack/hot/only-dev-server')); } else if (options.hot) { diff --git a/lib/utils/createConfig.js b/lib/utils/createConfig.js index 16ff397637..ade09cc641 100644 --- a/lib/utils/createConfig.js +++ b/lib/utils/createConfig.js @@ -30,6 +30,10 @@ function createConfig(config, argv, { port }) { options.socket = argv.socket; } + if (argv.sockPort) { + options.sockPort = argv.sockPort; + } + if (argv.progress) { options.progress = argv.progress; } diff --git a/test/Client.test.js b/test/Client.test.js index b0f4dc124f..cd4ff3157d 100644 --- a/test/Client.test.js +++ b/test/Client.test.js @@ -109,3 +109,41 @@ describe('Client complex inline script path', () => { }); }); }); + +describe('Client complex inline script path with sockPort', () => { + beforeAll((done) => { + const options = { + port: 9000, + host: '0.0.0.0', + inline: true, + watchOptions: { + poll: true, + }, + sockPath: '/foo/test/bar/', + sockPort: 8080, + }; + helper.startAwaitingCompilation(config, options, done); + }); + + afterAll(helper.close); + + describe('browser client', () => { + jest.setTimeout(30000); + + it('uses the correct sockPort', (done) => { + runBrowser().then(({ page, browser }) => { + page + .waitForRequest((requestObj) => + requestObj.url().match(/foo\/test\/bar/) + ) + .then((requestObj) => { + expect(requestObj.url()).toMatch( + /^http:\/\/localhost:8080\/foo\/test\/bar/ + ); + browser.close().then(done); + }); + page.goto('http://localhost:9000/main'); + }); + }); + }); +});