Skip to content

Commit 93e5103

Browse files
authored
refactor(server): remove some variables of options (#2175)
1 parent d0893f1 commit 93e5103

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
@@ -89,21 +89,7 @@ class Server {
8989

9090
this.sockets = [];
9191
this.contentBaseWatchers = [];
92-
93-
// TODO this.<property> is deprecated (remove them in next major release.) in favor this.options.<property>
9492
this.hot = this.options.hot || this.options.hotOnly;
95-
this.headers = this.options.headers;
96-
this.progress = this.options.progress;
97-
98-
this.serveIndex = this.options.serveIndex;
99-
100-
this.clientOverlay = this.options.overlay;
101-
this.clientLogLevel = this.options.clientLogLevel;
102-
103-
this.publicHost = this.options.public;
104-
this.allowedHosts = this.options.allowedHosts;
105-
this.disableHostCheck = !!this.options.disableHostCheck;
106-
10793
this.watchOptions = options.watchOptions || {};
10894

10995
// Replace leading and trailing slashes to normalize path
@@ -113,7 +99,7 @@ class Server {
11399
: 'sockjs-node'
114100
}`;
115101

116-
if (this.progress) {
102+
if (this.options.progress) {
117103
this.setupProgressPlugin();
118104
}
119105

@@ -536,9 +522,10 @@ class Server {
536522
}
537523

538524
// checking if it's set to true or not set (Default : undefined => true)
539-
this.serveIndex = this.serveIndex || this.serveIndex === undefined;
525+
this.options.serveIndex =
526+
this.options.serveIndex || this.options.serveIndex === undefined;
540527

541-
if (this.options.contentBase && this.serveIndex) {
528+
if (this.options.contentBase && this.options.serveIndex) {
542529
runnableFeatures.push('contentBaseIndex');
543530
}
544531

@@ -695,8 +682,8 @@ class Server {
695682
}
696683
});
697684

698-
if (this.clientLogLevel) {
699-
this.sockWrite([connection], 'log-level', this.clientLogLevel);
685+
if (this.options.clientLogLevel) {
686+
this.sockWrite([connection], 'log-level', this.options.clientLogLevel);
700687
}
701688

702689
if (this.hot) {
@@ -708,12 +695,12 @@ class Server {
708695
this.sockWrite([connection], 'liveReload', this.options.liveReload);
709696
}
710697

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

715-
if (this.clientOverlay) {
716-
this.sockWrite([connection], 'overlay', this.clientOverlay);
702+
if (this.options.overlay) {
703+
this.sockWrite([connection], 'overlay', this.options.overlay);
717704
}
718705

719706
if (!this._stats) {
@@ -806,10 +793,10 @@ class Server {
806793
}
807794

808795
setContentHeaders(req, res, next) {
809-
if (this.headers) {
796+
if (this.options.headers) {
810797
// eslint-disable-next-line
811-
for (const name in this.headers) {
812-
res.setHeader(name, this.headers[name]);
798+
for (const name in this.options.headers) {
799+
res.setHeader(name, this.options.headers[name]);
813800
}
814801
}
815802

@@ -825,8 +812,10 @@ class Server {
825812
}
826813

827814
checkHeaders(headers, headerToCheck) {
815+
const optionsDisableHostCheck = !!this.options.disableHostCheck;
816+
828817
// allow user to opt-out this security check, at own risk
829-
if (this.disableHostCheck) {
818+
if (optionsDisableHostCheck) {
830819
return true;
831820
}
832821

@@ -868,9 +857,13 @@ class Server {
868857
}
869858
// always allow localhost host, for convenience
870859
// allow if hostname is in allowedHosts
871-
if (this.allowedHosts && this.allowedHosts.length) {
872-
for (let hostIdx = 0; hostIdx < this.allowedHosts.length; hostIdx++) {
873-
const allowedHost = this.allowedHosts[hostIdx];
860+
if (this.options.allowedHosts && this.options.allowedHosts.length) {
861+
for (
862+
let hostIdx = 0;
863+
hostIdx < this.options.allowedHosts.length;
864+
hostIdx++
865+
) {
866+
const allowedHost = this.options.allowedHosts[hostIdx];
874867

875868
if (allowedHost === hostname) {
876869
return true;
@@ -892,10 +885,12 @@ class Server {
892885
}
893886

894887
// also allow public hostname if provided
895-
if (typeof this.publicHost === 'string') {
896-
const idxPublic = this.publicHost.indexOf(':');
888+
if (typeof this.options.public === 'string') {
889+
const idxPublic = this.options.public.indexOf(':');
897890
const publicHostname =
898-
idxPublic >= 0 ? this.publicHost.substr(0, idxPublic) : this.publicHost;
891+
idxPublic >= 0
892+
? this.options.public.substr(0, idxPublic)
893+
: this.options.public;
899894

900895
if (hostname === publicHostname) {
901896
return true;

0 commit comments

Comments
 (0)