Skip to content

refactor(server): remove some variables of options #2175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 28 additions & 33 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,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 @@ -113,7 +99,7 @@ class Server {
: 'sockjs-node'
}`;

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

Expand Down Expand Up @@ -536,9 +522,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 @@ -695,8 +682,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 @@ -708,12 +695,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 @@ -806,10 +793,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 @@ -825,8 +812,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 @@ -868,9 +857,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 @@ -892,10 +885,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