Skip to content

Commit 26165f9

Browse files
refactor: server access property name (#2879)
1 parent cf15e24 commit 26165f9

13 files changed

+57
-62
lines changed

lib/Server.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ class Server {
7070
this.createServer();
7171

7272
routes(this);
73-
killable(this.listeningApp);
73+
killable(this.server);
7474

7575
setupExitSignals(this);
7676

7777
// Proxy WebSocket without the initial http request
7878
// https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade
7979
// eslint-disable-next-line func-names
8080
this.websocketProxies.forEach(function (wsProxy) {
81-
this.listeningApp.on('upgrade', wsProxy.upgrade);
81+
this.server.on('upgrade', wsProxy.upgrade);
8282
}, this);
8383
}
8484

@@ -96,8 +96,8 @@ class Server {
9696

9797
this.sockWrite(this.sockets, 'progress-update', { percent, msg });
9898

99-
if (this.listeningApp) {
100-
this.listeningApp.emit('progress-update', { percent, msg });
99+
if (this.server) {
100+
this.server.emit('progress-update', { percent, msg });
101101
}
102102
}).apply(this.compiler);
103103
}
@@ -497,7 +497,7 @@ class Server {
497497
if (this.options.https) {
498498
if (this.options.http2) {
499499
// TODO: we need to replace spdy with http2 which is an internal module
500-
this.listeningApp = require('spdy').createServer(
500+
this.server = require('spdy').createServer(
501501
{
502502
...this.options.https,
503503
spdy: {
@@ -507,13 +507,13 @@ class Server {
507507
this.app
508508
);
509509
} else {
510-
this.listeningApp = https.createServer(this.options.https, this.app);
510+
this.server = https.createServer(this.options.https, this.app);
511511
}
512512
} else {
513-
this.listeningApp = http.createServer(this.app);
513+
this.server = http.createServer(this.app);
514514
}
515515

516-
this.listeningApp.on('error', (err) => {
516+
this.server.on('error', (err) => {
517517
throw err;
518518
});
519519
}
@@ -581,7 +581,7 @@ class Server {
581581

582582
showStatus() {
583583
const suffix = '/';
584-
const uri = `${createDomain(this.options, this.listeningApp)}${suffix}`;
584+
const uri = `${createDomain(this.options, this.server)}${suffix}`;
585585

586586
const configArr = getCompilerConfigArray(this.compiler);
587587
const colors = getColorsOption(configArr);
@@ -603,7 +603,7 @@ class Server {
603603
.then((port) => {
604604
this.port = port;
605605

606-
return this.listeningApp.listen(port, hostname, (err) => {
606+
return this.server.listen(port, hostname, (err) => {
607607
if (this.options.hot || this.options.liveReload) {
608608
this.createSocketServer();
609609
}
@@ -615,7 +615,7 @@ class Server {
615615
this.showStatus();
616616

617617
if (fn) {
618-
fn.call(this.listeningApp, err);
618+
fn.call(this.server, err);
619619
}
620620

621621
if (typeof this.options.onListening === 'function') {
@@ -625,7 +625,7 @@ class Server {
625625
})
626626
.catch((err) => {
627627
if (fn) {
628-
fn.call(this.listeningApp, err);
628+
fn.call(this.server, err);
629629
}
630630
})
631631
);
@@ -643,7 +643,7 @@ class Server {
643643
);
644644
this.staticWatchers = [];
645645

646-
this.listeningApp.kill(() => {
646+
this.server.kill(() => {
647647
// watchers must be closed before closing middleware
648648
prom.then(() => {
649649
this.middleware.close(cb);

lib/servers/SockJSServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = class SockJSServer extends (
4848
},
4949
});
5050

51-
this.socket.installHandlers(this.server.listeningApp, {
51+
this.socket.installHandlers(this.server.server, {
5252
prefix: this.server.options.client.path,
5353
});
5454
}

lib/servers/WebsocketServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = class WebsocketServer extends (
1717
path: this.server.options.client.path,
1818
});
1919

20-
this.server.listeningApp.on('upgrade', (req, sock, head) => {
20+
this.server.server.on('upgrade', (req, sock, head) => {
2121
if (!this.wsServer.shouldHandle(req)) {
2222
return;
2323
}

test/client/clients/SockJSClient.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ describe('SockJSClient', () => {
1616
const { log } = require('../../../client-src/default/utils/log');
1717
let consoleMock;
1818
let socketServer;
19-
let listeningApp;
19+
let server;
2020

2121
beforeAll((done) => {
2222
consoleMock = jest.spyOn(console, 'log').mockImplementation();
2323

2424
// eslint-disable-next-line new-cap
2525
const app = new express();
2626

27-
listeningApp = http.createServer(app);
28-
listeningApp.listen(port, 'localhost', () => {
27+
server = http.createServer(app);
28+
server.listen(port, 'localhost', () => {
2929
socketServer = sockjs.createServer();
30-
socketServer.installHandlers(listeningApp, {
30+
socketServer.installHandlers(server, {
3131
prefix: '/ws',
3232
});
3333
done();
@@ -75,7 +75,7 @@ describe('SockJSClient', () => {
7575
});
7676

7777
afterAll((done) => {
78-
listeningApp.close(() => {
78+
server.close(() => {
7979
done();
8080
});
8181
});

test/client/clients/WebsocketClient.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ describe('WebsocketClient', () => {
1515
const WebsocketClient = require('../../../client-src/clients/WebsocketClient');
1616
const { log } = require('../../../client-src/default/utils/log');
1717
let socketServer;
18-
let listeningApp;
18+
let server;
1919

2020
beforeAll((done) => {
2121
// eslint-disable-next-line new-cap
2222
const app = new express();
2323

24-
listeningApp = http.createServer(app);
25-
listeningApp.listen(port, 'localhost', () => {
24+
server = http.createServer(app);
25+
server.listen(port, 'localhost', () => {
2626
socketServer = new ws.Server({
27-
server: listeningApp,
27+
server,
2828
path: '/ws-server',
2929
});
3030
done();
@@ -68,7 +68,7 @@ describe('WebsocketClient', () => {
6868
});
6969

7070
afterAll((done) => {
71-
listeningApp.close(() => {
71+
server.close(() => {
7272
done();
7373
});
7474
});

test/server/Server.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,11 @@ describe('Server', () => {
8585
});
8686
});
8787

88-
it('test listeningApp error reporting', () => {
88+
it('test server error reporting', () => {
8989
const compiler = webpack(config);
9090
const server = new Server(compiler, baseDevConfig);
9191

92-
const emitError = () =>
93-
server.listeningApp.emit('error', new Error('Error !!!'));
92+
const emitError = () => server.server.emit('error', new Error('Error !!!'));
9493

9594
expect(emitError).toThrowError();
9695
});

test/server/host-option.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('host option', () => {
2525
});
2626

2727
it('server address', () => {
28-
const address = server.listeningApp.address();
28+
const address = server.server.address();
2929

3030
expect(address.address).toBe('127.0.0.1');
3131
expect(address.port).toBe(port);
@@ -56,7 +56,7 @@ describe('host option', () => {
5656
});
5757

5858
it('server address', () => {
59-
const address = server.listeningApp.address();
59+
const address = server.server.address();
6060

6161
expect(address.address).toBe('::');
6262
expect(address.port).toBe(port);
@@ -86,7 +86,7 @@ describe('host option', () => {
8686
});
8787

8888
it('server address', () => {
89-
const address = server.listeningApp.address();
89+
const address = server.server.address();
9090

9191
expect(address.address).toBe('::');
9292
expect(address.port).toBe(port);
@@ -116,7 +116,7 @@ describe('host option', () => {
116116
});
117117

118118
it('server address', () => {
119-
const address = server.listeningApp.address();
119+
const address = server.server.address();
120120

121121
expect(address.address).toBe('127.0.0.1');
122122
expect(address.port).toBe(port);
@@ -146,7 +146,7 @@ describe('host option', () => {
146146
});
147147

148148
it('server address', () => {
149-
const address = server.listeningApp.address();
149+
const address = server.server.address();
150150

151151
expect(address.address).toBe('127.0.0.1');
152152
expect(address.port).toBe(port);
@@ -176,7 +176,7 @@ describe('host option', () => {
176176
});
177177

178178
it('server address', () => {
179-
const address = server.listeningApp.address();
179+
const address = server.server.address();
180180

181181
expect(address.address).toBe('0.0.0.0');
182182
expect(address.port).toBe(port);

test/server/port-option.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('port', () => {
2525
});
2626

2727
it('server address', () => {
28-
const address = server.listeningApp.address();
28+
const address = server.server.address();
2929

3030
expect(address.address).toBe('127.0.0.1');
3131
// Random port
@@ -56,7 +56,7 @@ describe('port', () => {
5656
});
5757

5858
it('server address', () => {
59-
const address = server.listeningApp.address();
59+
const address = server.server.address();
6060

6161
expect(address.address).toBe('127.0.0.1');
6262
// Random port
@@ -86,7 +86,7 @@ describe('port', () => {
8686
});
8787

8888
it('server address', () => {
89-
const address = server.listeningApp.address();
89+
const address = server.server.address();
9090

9191
expect(address.address).toBe('127.0.0.1');
9292
// Random port
@@ -116,7 +116,7 @@ describe('port', () => {
116116
});
117117

118118
it('server address', () => {
119-
const address = server.listeningApp.address();
119+
const address = server.server.address();
120120

121121
expect(address.address).toBe('127.0.0.1');
122122
expect(address.port).toBe(33333);
@@ -145,7 +145,7 @@ describe('port', () => {
145145
});
146146

147147
it('server address', () => {
148-
const address = server.listeningApp.address();
148+
const address = server.server.address();
149149

150150
expect(address.address).toBe('127.0.0.1');
151151
expect(address.port).toBe(33333);

test/server/servers/SockJSServer.test.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ const port = require('../../ports-map').SockJSServer;
88

99
describe('SockJSServer', () => {
1010
let socketServer;
11-
let listeningApp;
11+
let server;
1212

1313
beforeEach((done) => {
1414
// eslint-disable-next-line new-cap
1515
const app = new express();
1616

17-
listeningApp = http.createServer(app);
18-
listeningApp.listen(port, 'localhost', () => {
19-
const server = {
17+
server = http.createServer(app);
18+
server.listen(port, 'localhost', () => {
19+
socketServer = new SockJSServer({
2020
logger: {
2121
error: () => {},
2222
log: () => {},
@@ -27,10 +27,8 @@ describe('SockJSServer', () => {
2727
path: '/ws',
2828
},
2929
},
30-
listeningApp,
31-
};
32-
33-
socketServer = new SockJSServer(server);
30+
server,
31+
});
3432

3533
done();
3634
});
@@ -103,6 +101,6 @@ describe('SockJSServer', () => {
103101
});
104102

105103
afterEach((done) => {
106-
listeningApp.close(done);
104+
server.close(done);
107105
});
108106
});

test/server/servers/WebsocketServer.test.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,24 @@ const WebsocketServer = require('../../../lib/servers/WebsocketServer');
77
const port = require('../../ports-map').WebsocketServer;
88

99
describe('WebsocketServer', () => {
10-
let server;
1110
let socketServer;
12-
let listeningApp;
11+
let server;
1312

1413
beforeEach((done) => {
1514
// eslint-disable-next-line new-cap
1615
const app = new express();
1716

18-
listeningApp = http.createServer(app);
19-
listeningApp.listen(port, 'localhost', () => {
20-
server = {
17+
server = http.createServer(app);
18+
server.listen(port, 'localhost', () => {
19+
socketServer = new WebsocketServer({
2120
options: {
2221
client: {
2322
path: '/ws-server',
2423
},
2524
},
26-
listeningApp,
25+
server,
2726
wsHeartbeatInterval: 800,
28-
};
29-
socketServer = new WebsocketServer(server);
27+
});
3028
done();
3129
});
3230
});
@@ -112,6 +110,6 @@ describe('WebsocketServer', () => {
112110
});
113111

114112
afterEach((done) => {
115-
listeningApp.close(done);
113+
server.close(done);
116114
});
117115
});

0 commit comments

Comments
 (0)