Skip to content

Commit c600b0e

Browse files
committed
refactor(server): remove some variables of options (#2175)
1 parent 1679797 commit c600b0e

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

@@ -530,9 +516,10 @@ class Server {
530516
}
531517

532518
// checking if it's set to true or not set (Default : undefined => true)
533-
this.serveIndex = this.serveIndex || this.serveIndex === undefined;
519+
this.options.serveIndex =
520+
this.options.serveIndex || this.options.serveIndex === undefined;
534521

535-
if (this.options.contentBase && this.serveIndex) {
522+
if (this.options.contentBase && this.options.serveIndex) {
536523
runnableFeatures.push('contentBaseIndex');
537524
}
538525

@@ -689,8 +676,8 @@ class Server {
689676
}
690677
});
691678

692-
if (this.clientLogLevel) {
693-
this.sockWrite([connection], 'log-level', this.clientLogLevel);
679+
if (this.options.clientLogLevel) {
680+
this.sockWrite([connection], 'log-level', this.options.clientLogLevel);
694681
}
695682

696683
if (this.hot) {
@@ -702,12 +689,12 @@ class Server {
702689
this.sockWrite([connection], 'liveReload', this.options.liveReload);
703690
}
704691

705-
if (this.progress) {
706-
this.sockWrite([connection], 'progress', this.progress);
692+
if (this.options.progress) {
693+
this.sockWrite([connection], 'progress', this.options.progress);
707694
}
708695

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

713700
if (!this._stats) {
@@ -800,10 +787,10 @@ class Server {
800787
}
801788

802789
setContentHeaders(req, res, next) {
803-
if (this.headers) {
790+
if (this.options.headers) {
804791
// eslint-disable-next-line
805-
for (const name in this.headers) {
806-
res.setHeader(name, this.headers[name]);
792+
for (const name in this.options.headers) {
793+
res.setHeader(name, this.options.headers[name]);
807794
}
808795
}
809796

@@ -819,8 +806,10 @@ class Server {
819806
}
820807

821808
checkHeaders(headers, headerToCheck) {
809+
const optionsDisableHostCheck = !!this.options.disableHostCheck;
810+
822811
// allow user to opt-out this security check, at own risk
823-
if (this.disableHostCheck) {
812+
if (optionsDisableHostCheck) {
824813
return true;
825814
}
826815

@@ -862,9 +851,13 @@ class Server {
862851
}
863852
// always allow localhost host, for convenience
864853
// allow if hostname is in allowedHosts
865-
if (this.allowedHosts && this.allowedHosts.length) {
866-
for (let hostIdx = 0; hostIdx < this.allowedHosts.length; hostIdx++) {
867-
const allowedHost = this.allowedHosts[hostIdx];
854+
if (this.options.allowedHosts && this.options.allowedHosts.length) {
855+
for (
856+
let hostIdx = 0;
857+
hostIdx < this.options.allowedHosts.length;
858+
hostIdx++
859+
) {
860+
const allowedHost = this.options.allowedHosts[hostIdx];
868861

869862
if (allowedHost === hostname) {
870863
return true;
@@ -886,10 +879,12 @@ class Server {
886879
}
887880

888881
// also allow public hostname if provided
889-
if (typeof this.publicHost === 'string') {
890-
const idxPublic = this.publicHost.indexOf(':');
882+
if (typeof this.options.public === 'string') {
883+
const idxPublic = this.options.public.indexOf(':');
891884
const publicHostname =
892-
idxPublic >= 0 ? this.publicHost.substr(0, idxPublic) : this.publicHost;
885+
idxPublic >= 0
886+
? this.options.public.substr(0, idxPublic)
887+
: this.options.public;
893888

894889
if (hostname === publicHostname) {
895890
return true;

0 commit comments

Comments
 (0)