diff --git a/lib/Server.js b/lib/Server.js index 9eb335764d..cc4e996280 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -89,21 +89,7 @@ class Server { this.sockets = []; this.contentBaseWatchers = []; - - // TODO this. is deprecated (remove them in next major release.) in favor this.options. 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 @@ -113,7 +99,7 @@ class Server { : 'sockjs-node' }`; - if (this.progress) { + if (this.options.progress) { this.setupProgressPlugin(); } @@ -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'); } @@ -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) { @@ -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) { @@ -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]); } } @@ -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; } @@ -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; @@ -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;