Skip to content
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

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

Merged
merged 12 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
8 changes: 7 additions & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,15 @@ class Server {

defaultFeatures.push('magicHtml');

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

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
3 changes: 3 additions & 0 deletions lib/options.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"type": "object",
"properties": {
"serveIndex": {
"type": "boolean"
},
"hot": {
"type": "boolean"
},
Expand Down