Skip to content

Commit

Permalink
Add opts.showDotfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
camwiegert committed Nov 10, 2015
1 parent 881f4b9 commit ff8471f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -105,6 +105,10 @@ If it is a function, it will be executed on every request, and passed the pathna

Turn **off** directory listings with `opts.showDir === false`. Defaults to **true**.

### `opts.showDotfiles`

Exclude dotfiles from directory listings with `opts.showDotfiles === false`. Defaults to **true**.

### `opts.humanReadable`

If showDir is enabled, add human-readable file sizes. Defaults to **true**.
Expand Down
1 change: 1 addition & 0 deletions lib/ecstatic/aliases.json
@@ -1,6 +1,7 @@
{
"autoIndex": [ "autoIndex", "autoindex" ],
"showDir": [ "showDir", "showdir" ],
"showDotfiles": ["showDotfiles", "showdotfiles"],
"humanReadable": [ "humanReadable", "humanreadable", "human-readable" ],
"si": [ "si", "index" ],
"handleError": [ "handleError", "handleerror" ],
Expand Down
1 change: 1 addition & 0 deletions lib/ecstatic/defaults.json
@@ -1,6 +1,7 @@
{
"autoIndex": true,
"showDir": true,
"showDotfiles": true,
"humanReadable": true,
"si": false,
"cache": "max-age=3600",
Expand Down
9 changes: 9 additions & 0 deletions lib/ecstatic/opts.js
Expand Up @@ -6,6 +6,7 @@ var aliases = require('./aliases.json')
module.exports = function (opts) {
var autoIndex = defaults.autoIndex,
showDir = defaults.showDir,
showDotfiles = defaults.showDotfiles,
humanReadable = defaults.humanReadable,
si = defaults.si,
cache = defaults.cache,
Expand Down Expand Up @@ -39,6 +40,13 @@ module.exports = function (opts) {
}
});

aliases.showDotfiles.some(function (k) {
if (isDeclared(k)) {
showDotfiles = opts[k];
return true;
}
});

aliases.humanReadable.some(function (k) {
if (isDeclared(k)) {
humanReadable = opts[k];
Expand Down Expand Up @@ -154,6 +162,7 @@ module.exports = function (opts) {
cache: cache,
autoIndex: autoIndex,
showDir: showDir,
showDotfiles: showDotfiles,
humanReadable: humanReadable,
si: si,
defaultExt: defaultExt,
Expand Down
9 changes: 9 additions & 0 deletions lib/ecstatic/showdir.js
Expand Up @@ -13,6 +13,7 @@ module.exports = function (opts, stat) {
baseDir = opts.baseDir,
humanReadable = opts.humanReadable,
handleError = opts.handleError,
showDotfiles = opts.showDotfiles,
si = opts.si,
weakEtags = opts.weakEtags;

Expand Down Expand Up @@ -40,6 +41,14 @@ module.exports = function (opts, stat) {
if (err) {
return handleError ? status[500](res, next, { error: err }) : next();
}

// Optionally exclude dotfiles from directory listing.
if (!showDotfiles) {
files = files.filter(function(filename){
return filename.slice(0,1) !== '.';
});
}

res.setHeader('content-type', 'text/html');
res.setHeader('etag', etag(stat, weakEtags));
res.setHeader('last-modified', (new Date(stat.mtime)).toUTCString());
Expand Down

0 comments on commit ff8471f

Please sign in to comment.