Skip to content

Commit fb1e2b1

Browse files
hiroppyalexander-akait
authored andcommitted
refactor(server): remove some variables of options (#2175)
1 parent f183913 commit fb1e2b1

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

lib/Server.js

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,7 @@ class Server {
8484

8585
this.sockets = [];
8686
this.contentBaseWatchers = [];
87-
88-
// TODO this.<property> is deprecated (remove them in next major release.) in favor this.options.<property>
8987
this.hot = this.options.hot || this.options.hotOnly;
90-
this.headers = this.options.headers;
91-
this.progress = this.options.progress;
92-
93-
this.serveIndex = this.options.serveIndex;
94-
95-
this.clientOverlay = this.options.overlay;
96-
this.clientLogLevel = this.options.clientLogLevel;
97-
98-
this.publicHost = this.options.public;
99-
this.allowedHosts = this.options.allowedHosts;
100-
this.disableHostCheck = !!this.options.disableHostCheck;
101-
10288
this.watchOptions = options.watchOptions || {};
10389

10490
// Replace leading and trailing slashes to normalize path
@@ -108,7 +94,7 @@ class Server {
10894
: 'sockjs-node'
10995
}`;
11096

111-
if (this.progress) {
97+
if (this.options.progress) {
11298
this.setupProgressPlugin();
11399
}
114100

@@ -547,9 +533,10 @@ class Server {
547533
}
548534

549535
// checking if it's set to true or not set (Default : undefined => true)
550-
this.serveIndex = this.serveIndex || this.serveIndex === undefined;
536+
this.options.serveIndex =
537+
this.options.serveIndex || this.options.serveIndex === undefined;
551538

552-
if (this.options.contentBase && this.serveIndex) {
539+
if (this.options.contentBase && this.options.serveIndex) {
553540
runnableFeatures.push('contentBaseIndex');
554541
}
555542

@@ -706,8 +693,8 @@ class Server {
706693
}
707694
});
708695

709-
if (this.clientLogLevel) {
710-
this.sockWrite([connection], 'log-level', this.clientLogLevel);
696+
if (this.options.clientLogLevel) {
697+
this.sockWrite([connection], 'log-level', this.options.clientLogLevel);
711698
}
712699

713700
if (this.hot) {
@@ -719,12 +706,12 @@ class Server {
719706
this.sockWrite([connection], 'liveReload', this.options.liveReload);
720707
}
721708

722-
if (this.progress) {
723-
this.sockWrite([connection], 'progress', this.progress);
709+
if (this.options.progress) {
710+
this.sockWrite([connection], 'progress', this.options.progress);
724711
}
725712

726-
if (this.clientOverlay) {
727-
this.sockWrite([connection], 'overlay', this.clientOverlay);
713+
if (this.options.overlay) {
714+
this.sockWrite([connection], 'overlay', this.options.overlay);
728715
}
729716

730717
if (!this._stats) {
@@ -817,10 +804,10 @@ class Server {
817804
}
818805

819806
setContentHeaders(req, res, next) {
820-
if (this.headers) {
807+
if (this.options.headers) {
821808
// eslint-disable-next-line
822-
for (const name in this.headers) {
823-
res.setHeader(name, this.headers[name]);
809+
for (const name in this.options.headers) {
810+
res.setHeader(name, this.options.headers[name]);
824811
}
825812
}
826813

@@ -836,8 +823,10 @@ class Server {
836823
}
837824

838825
checkHeaders(headers, headerToCheck) {
826+
const optionsDisableHostCheck = !!this.options.disableHostCheck;
827+
839828
// allow user to opt-out this security check, at own risk
840-
if (this.disableHostCheck) {
829+
if (optionsDisableHostCheck) {
841830
return true;
842831
}
843832

@@ -879,9 +868,13 @@ class Server {
879868
}
880869
// always allow localhost host, for convenience
881870
// allow if hostname is in allowedHosts
882-
if (this.allowedHosts && this.allowedHosts.length) {
883-
for (let hostIdx = 0; hostIdx < this.allowedHosts.length; hostIdx++) {
884-
const allowedHost = this.allowedHosts[hostIdx];
871+
if (this.options.allowedHosts && this.options.allowedHosts.length) {
872+
for (
873+
let hostIdx = 0;
874+
hostIdx < this.options.allowedHosts.length;
875+
hostIdx++
876+
) {
877+
const allowedHost = this.options.allowedHosts[hostIdx];
885878

886879
if (allowedHost === hostname) {
887880
return true;
@@ -903,10 +896,12 @@ class Server {
903896
}
904897

905898
// also allow public hostname if provided
906-
if (typeof this.publicHost === 'string') {
907-
const idxPublic = this.publicHost.indexOf(':');
899+
if (typeof this.options.public === 'string') {
900+
const idxPublic = this.options.public.indexOf(':');
908901
const publicHostname =
909-
idxPublic >= 0 ? this.publicHost.substr(0, idxPublic) : this.publicHost;
902+
idxPublic >= 0
903+
? this.options.public.substr(0, idxPublic)
904+
: this.options.public;
910905

911906
if (hostname === publicHostname) {
912907
return true;

0 commit comments

Comments
 (0)