Skip to content

Commit 732e6c5

Browse files
knagaitsevevilebottnawi
authored andcommitted
Fix: default to localhost when no host option (#1750)
1 parent 9f899ff commit 732e6c5

File tree

6 files changed

+59
-33
lines changed

6 files changed

+59
-33
lines changed

examples/api/middleware/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { setup } = require('../../util');
66

77
module.exports = setup({
88
context: __dirname,
9-
entry: ['./app.js', '../../../client/index.js?http://localhost:8080/'],
9+
entry: './app.js',
1010
output: {
1111
filename: 'bundle.js',
1212
},

examples/api/simple/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { setup } = require('../../util');
66

77
module.exports = setup({
88
context: __dirname,
9-
entry: ['./app.js', '../../../client/index.js?http://localhost:8080/'],
9+
entry: './app.js',
1010
output: {
1111
filename: 'bundle.js',
1212
},

lib/utils/createDomain.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function createDomain(options, server) {
77
const protocol = options.https ? 'https' : 'http';
88
const hostname = options.useLocalIp
99
? ip.v4.sync() || 'localhost'
10-
: options.host;
10+
: options.host || 'localhost';
1111

1212
// eslint-disable-next-line no-nested-ternary
1313
const port = options.socket ? 0 : server ? server.address().port : 0;

package-lock.json

+11-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/Client.test.js

+38
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,41 @@ describe('Client code', () => {
7171
});
7272
});
7373
});
74+
75+
describe('Client complex inline script path', () => {
76+
beforeAll((done) => {
77+
const options = {
78+
port: 9000,
79+
host: '0.0.0.0',
80+
inline: true,
81+
watchOptions: {
82+
poll: true,
83+
},
84+
public: 'myhost.test',
85+
sockPath: '/foo/test/bar/',
86+
};
87+
helper.startAwaitingCompilation(config, options, done);
88+
});
89+
90+
afterAll(helper.close);
91+
92+
describe('browser client', () => {
93+
jest.setTimeout(30000);
94+
95+
it('uses the correct public hostname and sockPath', (done) => {
96+
runBrowser().then(({ page, browser }) => {
97+
page
98+
.waitForRequest((requestObj) =>
99+
requestObj.url().match(/foo\/test\/bar/)
100+
)
101+
.then((requestObj) => {
102+
expect(requestObj.url()).toMatch(
103+
/^http:\/\/myhost\.test:9000\/foo\/test\/bar/
104+
);
105+
browser.close().then(done);
106+
});
107+
page.goto('http://localhost:9000/main');
108+
});
109+
});
110+
});
111+
});

test/Util.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ describe('check utility functions', () => {
3232
},
3333
expected: 'http://localhost:8080',
3434
},
35+
{
36+
name: 'no host option',
37+
options: {
38+
port: 8080,
39+
},
40+
expected: 'http://localhost:8080',
41+
},
3542
{
3643
name: 'https',
3744
options: {

0 commit comments

Comments
 (0)