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

feat: add sockPort options in queryString #1792

Merged
merged 2 commits into from Apr 16, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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');
});
});
});
});