Skip to content

Commit 958c841

Browse files
committed
refactor(server): remove some variables of options (#2175)
1 parent b132f7b commit 958c841

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
@@ -83,21 +83,7 @@ class Server {
8383

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

10389
// Replace leading and trailing slashes to normalize path
@@ -107,7 +93,7 @@ class Server {
10793
: 'sockjs-node'
10894
}`;
10995

110-
if (this.progress) {
96+
if (this.options.progress) {
11197
this.setupProgressPlugin();
11298
}
11399

@@ -532,9 +518,10 @@ class Server {
532518
}
533519

534520
// checking if it's set to true or not set (Default : undefined => true)
535-
this.serveIndex = this.serveIndex || this.serveIndex === undefined;
521+
this.options.serveIndex =
522+
this.options.serveIndex || this.options.serveIndex === undefined;
536523

537-
if (this.options.contentBase && this.serveIndex) {
524+
if (this.options.contentBase && this.options.serveIndex) {
538525
runnableFeatures.push('contentBaseIndex');
539526
}
540527

@@ -691,8 +678,8 @@ class Server {
691678
}
692679
});
693680

694-
if (this.clientLogLevel) {
695-
this.sockWrite([connection], 'log-level', this.clientLogLevel);
681+
if (this.options.clientLogLevel) {
682+
this.sockWrite([connection], 'log-level', this.options.clientLogLevel);
696683
}
697684

698685
if (this.hot) {
@@ -704,12 +691,12 @@ class Server {
704691
this.sockWrite([connection], 'liveReload', this.options.liveReload);
705692
}
706693

707-
if (this.progress) {
708-
this.sockWrite([connection], 'progress', this.progress);
694+
if (this.options.progress) {
695+
this.sockWrite([connection], 'progress', this.options.progress);
709696
}
710697

711-
if (this.clientOverlay) {
712-
this.sockWrite([connection], 'overlay', this.clientOverlay);
698+
if (this.options.overlay) {
699+
this.sockWrite([connection], 'overlay', this.options.overlay);
713700
}
714701

715702
if (!this._stats) {
@@ -802,10 +789,10 @@ class Server {
802789
}
803790

804791
setContentHeaders(req, res, next) {
805-
if (this.headers) {
792+
if (this.options.headers) {
806793
// eslint-disable-next-line
807-
for (const name in this.headers) {
808-
res.setHeader(name, this.headers[name]);
794+
for (const name in this.options.headers) {
795+
res.setHeader(name, this.options.headers[name]);
809796
}
810797
}
811798

@@ -821,8 +808,10 @@ class Server {
821808
}
822809

823810
checkHeaders(headers, headerToCheck) {
811+
const optionsDisableHostCheck = !!this.options.disableHostCheck;
812+
824813
// allow user to opt-out this security check, at own risk
825-
if (this.disableHostCheck) {
814+
if (optionsDisableHostCheck) {
826815
return true;
827816
}
828817

@@ -864,9 +853,13 @@ class Server {
864853
}
865854
// always allow localhost host, for convenience
866855
// allow if hostname is in allowedHosts
867-
if (this.allowedHosts && this.allowedHosts.length) {
868-
for (let hostIdx = 0; hostIdx < this.allowedHosts.length; hostIdx++) {
869-
const allowedHost = this.allowedHosts[hostIdx];
856+
if (this.options.allowedHosts && this.options.allowedHosts.length) {
857+
for (
858+
let hostIdx = 0;
859+
hostIdx < this.options.allowedHosts.length;
860+
hostIdx++
861+
) {
862+
const allowedHost = this.options.allowedHosts[hostIdx];
870863

871864
if (allowedHost === hostname) {
872865
return true;
@@ -888,10 +881,12 @@ class Server {
888881
}
889882

890883
// also allow public hostname if provided
891-
if (typeof this.publicHost === 'string') {
892-
const idxPublic = this.publicHost.indexOf(':');
884+
if (typeof this.options.public === 'string') {
885+
const idxPublic = this.options.public.indexOf(':');
893886
const publicHostname =
894-
idxPublic >= 0 ? this.publicHost.substr(0, idxPublic) : this.publicHost;
887+
idxPublic >= 0
888+
? this.options.public.substr(0, idxPublic)
889+
: this.options.public;
895890

896891
if (hostname === publicHostname) {
897892
return true;

0 commit comments

Comments
 (0)