Skip to content

Commit

Permalink
refactor(server): remove some variables of options (#2175)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Dec 18, 2019
1 parent 177c686 commit 99d089d
Showing 1 changed file with 28 additions and 33 deletions.
61 changes: 28 additions & 33 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,7 @@ class Server {

this.sockets = [];
this.contentBaseWatchers = [];

// TODO this.<property> is deprecated (remove them in next major release.) in favor this.options.<property>
this.hot = this.options.hot || this.options.hotOnly;
this.headers = this.options.headers;
this.progress = this.options.progress;

this.serveIndex = this.options.serveIndex;

this.clientOverlay = this.options.overlay;
this.clientLogLevel = this.options.clientLogLevel;

this.publicHost = this.options.public;
this.allowedHosts = this.options.allowedHosts;
this.disableHostCheck = !!this.options.disableHostCheck;

this.watchOptions = options.watchOptions || {};

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

if (this.progress) {
if (this.options.progress) {
this.setupProgressPlugin();
}

Expand Down Expand Up @@ -532,9 +518,10 @@ class Server {
}

// checking if it's set to true or not set (Default : undefined => true)
this.serveIndex = this.serveIndex || this.serveIndex === undefined;
this.options.serveIndex =
this.options.serveIndex || this.options.serveIndex === undefined;

if (this.options.contentBase && this.serveIndex) {
if (this.options.contentBase && this.options.serveIndex) {
runnableFeatures.push('contentBaseIndex');
}

Expand Down Expand Up @@ -691,8 +678,8 @@ class Server {
}
});

if (this.clientLogLevel) {
this.sockWrite([connection], 'log-level', this.clientLogLevel);
if (this.options.clientLogLevel) {
this.sockWrite([connection], 'log-level', this.options.clientLogLevel);
}

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

if (this.progress) {
this.sockWrite([connection], 'progress', this.progress);
if (this.options.progress) {
this.sockWrite([connection], 'progress', this.options.progress);
}

if (this.clientOverlay) {
this.sockWrite([connection], 'overlay', this.clientOverlay);
if (this.options.overlay) {
this.sockWrite([connection], 'overlay', this.options.overlay);
}

if (!this._stats) {
Expand Down Expand Up @@ -802,10 +789,10 @@ class Server {
}

setContentHeaders(req, res, next) {
if (this.headers) {
if (this.options.headers) {
// eslint-disable-next-line
for (const name in this.headers) {
res.setHeader(name, this.headers[name]);
for (const name in this.options.headers) {
res.setHeader(name, this.options.headers[name]);
}
}

Expand All @@ -821,8 +808,10 @@ class Server {
}

checkHeaders(headers, headerToCheck) {
const optionsDisableHostCheck = !!this.options.disableHostCheck;

// allow user to opt-out this security check, at own risk
if (this.disableHostCheck) {
if (optionsDisableHostCheck) {
return true;
}

Expand Down Expand Up @@ -864,9 +853,13 @@ class Server {
}
// always allow localhost host, for convenience
// allow if hostname is in allowedHosts
if (this.allowedHosts && this.allowedHosts.length) {
for (let hostIdx = 0; hostIdx < this.allowedHosts.length; hostIdx++) {
const allowedHost = this.allowedHosts[hostIdx];
if (this.options.allowedHosts && this.options.allowedHosts.length) {
for (
let hostIdx = 0;
hostIdx < this.options.allowedHosts.length;
hostIdx++
) {
const allowedHost = this.options.allowedHosts[hostIdx];

if (allowedHost === hostname) {
return true;
Expand All @@ -888,10 +881,12 @@ class Server {
}

// also allow public hostname if provided
if (typeof this.publicHost === 'string') {
const idxPublic = this.publicHost.indexOf(':');
if (typeof this.options.public === 'string') {
const idxPublic = this.options.public.indexOf(':');
const publicHostname =
idxPublic >= 0 ? this.publicHost.substr(0, idxPublic) : this.publicHost;
idxPublic >= 0
? this.options.public.substr(0, idxPublic)
: this.options.public;

if (hostname === publicHostname) {
return true;
Expand Down

0 comments on commit 99d089d

Please sign in to comment.