Skip to content

Feature: add option "serveIndex" to enable/disable serveIndex middleware #1752

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 12 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add the option with the default value to options.js & simplifying the…
… condition
  • Loading branch information
EslamHiko committed Apr 3, 2019
commit bee7cbc4130860592f8c3b99d76460dccda081ff
5 changes: 5 additions & 0 deletions bin/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const options = {
type: 'boolean',
describe: 'Lazy',
},
serveIndex: {
type: 'boolean',
describe: 'Enables/Disables serveIndex middleware',
default: true,
},
inline: {
type: 'boolean',
default: true,
Expand Down
13 changes: 7 additions & 6 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ class Server {
this.clientOverlay = options.overlay;
this.clientLogLevel = options.clientLogLevel;

this.serveIndex = options.serveIndex;

this.publicHost = options.public;
this.allowedHosts = options.allowedHosts;
this.disableHostCheck = !!options.disableHostCheck;
Expand Down Expand Up @@ -553,12 +551,15 @@ class Server {

defaultFeatures.push('magicHtml');

if (
contentBase !== false &&
(options.serveIndex || options.serveIndex === undefined)
) {
// checking if it's set to true or not set (Default : undefined => true)
options.serveIndex = options.serveIndex || options.serveIndex === undefined;
Copy link
Member

@alexander-akait alexander-akait Apr 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better avoid modify options because code below also can use options and modification original options is not good idea better keep this in separate variable, it is good practice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilebottnawi thank you for the advice, I set the option value to a separate variable this.serveIndex


const shouldHandleServeIndex = contentBase && options.serveIndex;

if (shouldHandleServeIndex) {
defaultFeatures.push('contentBaseIndex');
}

// compress is placed last and uses unshift so that it will be the first middleware used
if (options.compress) {
defaultFeatures.unshift('compress');
Expand Down