committed by
Douglas Christopher Wilson
parent
5e050a7d23
commit
cececc8c2e
@@ -1,6 +1,7 @@
|
||||
unreleased
|
||||
==========
|
||||
|
||||
* Add `dir` argument to `filter` function
|
||||
* Support using tokens multiple times
|
||||
|
||||
1.3.1 / 2014-10-01
|
||||
|
||||
@@ -35,7 +35,11 @@ Serve index accepts these properties in the options object.
|
||||
|
||||
##### filter
|
||||
|
||||
Apply this filter function to files. Defaults to `false`.
|
||||
Apply this filter function to files. Defaults to `false`. The `filter` function
|
||||
is called for each file, with the signature `filter(filename, index, files, dir)`
|
||||
where `filename` is the name of the file, `index` is the array index, `files` is
|
||||
the array of files and `dir` is the absolute path the file is located (and thus,
|
||||
the directory the listing is for).
|
||||
|
||||
##### hidden
|
||||
|
||||
|
||||
@@ -142,7 +142,9 @@ exports = module.exports = function serveIndex(root, options){
|
||||
fs.readdir(path, function(err, files){
|
||||
if (err) return next(err);
|
||||
if (!hidden) files = removeHidden(files);
|
||||
if (filter) files = files.filter(filter);
|
||||
if (filter) files = files.filter(function(filename, index, list) {
|
||||
return filter(filename, index, list, path);
|
||||
});
|
||||
files.sort();
|
||||
|
||||
// content-negotiation
|
||||
|
||||
@@ -264,6 +264,26 @@ describe('serveIndex(root)', function () {
|
||||
done()
|
||||
});
|
||||
});
|
||||
|
||||
it('should filter directory paths', function (done) {
|
||||
var seen = false
|
||||
var server = createServer(fixtures, {'filter': filter})
|
||||
|
||||
function filter(name, index, list, dir) {
|
||||
if (path.normalize(dir) === path.normalize(path.join(fixtures, '/users'))) {
|
||||
seen = true
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/users')
|
||||
.expect(200, function (err, res) {
|
||||
if (err) return done(err)
|
||||
seen.should.be.true
|
||||
done()
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with "icons" option', function () {
|
||||
|
||||
Reference in New Issue
Block a user