diff --git a/lib/Server.js b/lib/Server.js index 5bd30ee34a..76a16298b9 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -521,51 +521,49 @@ class Server { }, }; - const defaultFeatures = ['setup', 'before', 'headers', 'middleware']; + const runnableFeatures = []; - if (this.options.proxy) { - defaultFeatures.push('proxy', 'middleware'); + // compress is placed last and uses unshift so that it will be the first middleware used + if (this.options.compress) { + runnableFeatures.push('compress'); } - const contentBase = this.options.contentBase; + runnableFeatures.push('setup', 'before', 'headers', 'middleware'); - if (contentBase !== false) { - defaultFeatures.push('contentBaseFiles'); + if (this.options.proxy) { + runnableFeatures.push('proxy', 'middleware'); } - if (this.options.watchContentBase) { - defaultFeatures.push('watchContentBase'); + if (this.options.contentBase !== false) { + runnableFeatures.push('contentBaseFiles'); } if (this.options.historyApiFallback) { - defaultFeatures.push('historyApiFallback', 'middleware'); + runnableFeatures.push('historyApiFallback', 'middleware'); - if (contentBase !== false) { - defaultFeatures.push('contentBaseFiles'); + if (this.options.contentBase !== false) { + runnableFeatures.push('contentBaseFiles'); } } - defaultFeatures.push('magicHtml'); - // checking if it's set to true or not set (Default : undefined => true) this.serveIndex = this.serveIndex || this.serveIndex === undefined; - const shouldHandleServeIndex = contentBase && this.serveIndex; - - if (shouldHandleServeIndex) { - defaultFeatures.push('contentBaseIndex'); + if (this.options.contentBase && this.serveIndex) { + runnableFeatures.push('contentBaseIndex'); } - // compress is placed last and uses unshift so that it will be the first middleware used - if (this.options.compress) { - defaultFeatures.unshift('compress'); + if (this.options.watchContentBase) { + runnableFeatures.push('watchContentBase'); } + runnableFeatures.push('magicHtml'); + if (this.options.after) { - defaultFeatures.push('after'); + runnableFeatures.push('after'); } - (this.options.features || defaultFeatures).forEach((feature) => { + (this.options.features || runnableFeatures).forEach((feature) => { features[feature](); }); }