Skip to content

Commit 61b949e

Browse files
committed
fix: add hostname and port to bonjour name to prevent name collisions
1 parent 6d1f24f commit 61b949e

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/utils/runBonjour.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
function runBonjour({ port }) {
44
const bonjour = require('bonjour')();
5+
const os = require('os');
56

67
bonjour.publish({
7-
name: 'Webpack Dev Server',
8+
name: `Webpack Dev Server ${os.hostname()}:${port}`,
89
port,
910
type: 'http',
1011
subtypes: ['webpack'],

test/server/utils/__snapshots__/ runBonjour.test.js.snap renamed to test/server/utils/__snapshots__/runBonjour.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`runBonjour should call bonjour.publish 1`] = `
44
Object {
5-
"name": "Webpack Dev Server",
5+
"name": "Webpack Dev Server hostname:1111",
66
"port": 1111,
77
"subtypes": Array [
88
"webpack",

test/server/utils/ runBonjour.test.js renamed to test/server/utils/runBonjour.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
const runBonjour = require('../../../lib/utils/runBonjour');
44

5+
jest.mock('os', () => {
6+
return {
7+
hostname: () => 'hostname',
8+
};
9+
});
10+
511
describe('runBonjour', () => {
612
let mock;
713
let publish = jest.fn();
@@ -32,4 +38,16 @@ describe('runBonjour', () => {
3238

3339
expect(publish.mock.calls[0][0]).toMatchSnapshot();
3440
});
41+
42+
it('should call bonjour.publish with different name for different ports', () => {
43+
runBonjour({
44+
port: 1111,
45+
});
46+
47+
runBonjour({
48+
port: 2222,
49+
});
50+
51+
expect(publish.mock.calls[0][0].name).not.toEqual(publish.mock.calls[1][0].name);
52+
});
3553
});

0 commit comments

Comments
 (0)