Skip to content

Commit 9a4fafb

Browse files
feat: minor refactor
1 parent d3da508 commit 9a4fafb

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

lib/Server.js

+18-22
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,8 @@ class Server {
6666

6767
this.log = _log || createLogger(options);
6868

69-
// set serverMode default
70-
if (this.options.serverMode === undefined) {
71-
this.options.serverMode = 'sockjs';
72-
} else {
73-
this.log.warn(
74-
'serverMode is an experimental option, meaning its usage could potentially change without warning'
75-
);
76-
}
77-
// set clientMode default
78-
if (this.options.clientMode === undefined) {
79-
this.options.clientMode = 'sockjs';
80-
} else {
81-
this.log.warn(
82-
'clientMode is an experimental option, meaning its usage could potentially change without warning'
83-
);
84-
}
69+
// set client and server default mode
70+
this.setDefaultMode();
8571

8672
updateCompiler(this.compiler, this.options);
8773

@@ -153,6 +139,18 @@ class Server {
153139
}, this);
154140
}
155141

142+
setDefaultMode() {
143+
['serverMode', 'clientMode'].forEach((mode) => {
144+
if (this.options[mode] === undefined) {
145+
this.options[mode] = 'sockjs';
146+
} else {
147+
this.log.warn(
148+
`${mode} is an experimental option, meaning its usage could potentially change without warning`
149+
);
150+
}
151+
});
152+
}
153+
156154
setupProgressPlugin() {
157155
// for CLI output
158156
new webpack.ProgressPlugin({
@@ -292,14 +290,12 @@ class Server {
292290
* ]
293291
*/
294292
this.options.proxy.forEach((proxyConfigOrCallback) => {
295-
let proxyConfig;
296293
let proxyMiddleware;
297294

298-
if (typeof proxyConfigOrCallback === 'function') {
299-
proxyConfig = proxyConfigOrCallback();
300-
} else {
301-
proxyConfig = proxyConfigOrCallback;
302-
}
295+
let proxyConfig =
296+
typeof proxyConfigOrCallback === 'function'
297+
? proxyConfigOrCallback()
298+
: proxyConfigOrCallback;
303299

304300
proxyMiddleware = getProxyMiddleware(proxyConfig);
305301

0 commit comments

Comments
 (0)