Skip to content

Commit

Permalink
feat: add sockPort option (#1792)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyuang authored and evilebottnawi committed Apr 16, 2019
1 parent 11bda15 commit 58d1682
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,3 +9,4 @@ client
coverage
ssl/*.pem
node_modules
.vscode
6 changes: 4 additions & 2 deletions client-src/default/index.js
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions lib/options.json
Expand Up @@ -67,6 +67,19 @@
"sockPath": {
"type": "string"
},
"sockPort": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
},
{
"type": "null"
}
]
},
"watchOptions": {
"type": "object"
},
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/addEntries.js
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/createConfig.js
Expand Up @@ -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;
}
Expand Down
38 changes: 38 additions & 0 deletions test/Client.test.js
Expand Up @@ -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');
});
});
});
});

0 comments on commit 58d1682

Please sign in to comment.