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/remove contentBaseIndex feature to/from defaultFeatures using ser…
…veIndex Option
  • Loading branch information
EslamHiko committed Apr 3, 2019
commit c3e4aca83f1a5f0dcd69913ad2066cbf34eeabd0
1 change: 0 additions & 1 deletion examples/api/simple/folder/simple.txt

This file was deleted.

25 changes: 13 additions & 12 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,15 @@ class Server {
}
},
contentBaseIndex: () => {
if (this.serveIndex || typeof this.serveIndex === 'undefined') {
if (Array.isArray(contentBase)) {
contentBase.forEach((item) => {
app.get('*', serveIndex(item));
});
} else if (
!/^(https?:)?\/\//.test(contentBase) &&
typeof contentBase !== 'number'
) {
app.get('*', serveIndex(contentBase));
}
if (Array.isArray(contentBase)) {
contentBase.forEach((item) => {
app.get('*', serveIndex(item));
});
} else if (
!/^(https?:)?\/\//.test(contentBase) &&
typeof contentBase !== 'number'
) {
app.get('*', serveIndex(contentBase));
}
},
watchContentBase: () => {
Expand Down Expand Up @@ -555,7 +553,10 @@ class Server {

defaultFeatures.push('magicHtml');

if (contentBase !== false) {
if (
contentBase !== false &&
(options.serveIndex || typeof 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.

Don't use typeof, we prefer using !

Copy link
Member Author

Choose a reason for hiding this comment

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

      (options.serveIndex || options.serveIndex === undefined)

@evilebottnawi done

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