Skip to content

Commit

Permalink
Fix: default to localhost when no host option (#1750)
Browse files Browse the repository at this point in the history
  • Loading branch information
knagaitsev authored and evilebottnawi committed Apr 3, 2019
1 parent 9f899ff commit 732e6c5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 33 deletions.
2 changes: 1 addition & 1 deletion examples/api/middleware/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { setup } = require('../../util');

module.exports = setup({
context: __dirname,
entry: ['./app.js', '../../../client/index.js?http://localhost:8080/'],
entry: './app.js',
output: {
filename: 'bundle.js',
},
Expand Down
2 changes: 1 addition & 1 deletion examples/api/simple/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { setup } = require('../../util');

module.exports = setup({
context: __dirname,
entry: ['./app.js', '../../../client/index.js?http://localhost:8080/'],
entry: './app.js',
output: {
filename: 'bundle.js',
},
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/createDomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function createDomain(options, server) {
const protocol = options.https ? 'https' : 'http';
const hostname = options.useLocalIp
? ip.v4.sync() || 'localhost'
: options.host;
: options.host || 'localhost';

// eslint-disable-next-line no-nested-ternary
const port = options.socket ? 0 : server ? server.address().port : 0;
Expand Down
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions test/Client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,41 @@ describe('Client code', () => {
});
});
});

describe('Client complex inline script path', () => {
beforeAll((done) => {
const options = {
port: 9000,
host: '0.0.0.0',
inline: true,
watchOptions: {
poll: true,
},
public: 'myhost.test',
sockPath: '/foo/test/bar/',
};
helper.startAwaitingCompilation(config, options, done);
});

afterAll(helper.close);

describe('browser client', () => {
jest.setTimeout(30000);

it('uses the correct public hostname and sockPath', (done) => {
runBrowser().then(({ page, browser }) => {
page
.waitForRequest((requestObj) =>
requestObj.url().match(/foo\/test\/bar/)
)
.then((requestObj) => {
expect(requestObj.url()).toMatch(
/^http:\/\/myhost\.test:9000\/foo\/test\/bar/
);
browser.close().then(done);
});
page.goto('http://localhost:9000/main');
});
});
});
});
7 changes: 7 additions & 0 deletions test/Util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ describe('check utility functions', () => {
},
expected: 'http://localhost:8080',
},
{
name: 'no host option',
options: {
port: 8080,
},
expected: 'http://localhost:8080',
},
{
name: 'https',
options: {
Expand Down

0 comments on commit 732e6c5

Please sign in to comment.