Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47b3884bbe | ||
|
|
5b2ff74554 | ||
|
|
7dc0ff4d97 | ||
|
|
1bdd53c05d | ||
|
|
dce12186f8 | ||
|
|
838ee4cc02 | ||
|
|
f332e6e576 | ||
|
|
b866f9690a | ||
|
|
ac94303941 | ||
|
|
cececc8c2e | ||
|
|
5e050a7d23 | ||
|
|
5731ebee6b | ||
|
|
c6b9d3bdbf | ||
|
|
4686c18e1d | ||
|
|
8a06bb7e19 | ||
|
|
effbe1a4b0 | ||
|
|
351c226736 | ||
|
|
1b098fb723 | ||
|
|
8880a8b80a | ||
|
|
276b52782a | ||
|
|
591fd9ca13 | ||
|
|
857b37aad4 | ||
|
|
40a38e688d | ||
|
|
874d32748b |
42
HISTORY.md
42
HISTORY.md
@@ -1,3 +1,45 @@
|
||||
1.5.0 / 2014-10-16
|
||||
==================
|
||||
|
||||
* Create errors with `http-errors`
|
||||
* deps: debug@~2.1.0
|
||||
- Implement `DEBUG_FD` env variable support
|
||||
* deps: mime-types@~2.0.2
|
||||
- deps: mime-db@~1.1.0
|
||||
|
||||
1.4.1 / 2014-10-15
|
||||
==================
|
||||
|
||||
* deps: accepts@~1.1.2
|
||||
- Fix error when media type has invalid parameter
|
||||
- deps: negotiator@0.4.9
|
||||
|
||||
1.4.0 / 2014-10-03
|
||||
==================
|
||||
|
||||
* Add `dir` argument to `filter` function
|
||||
* Support using tokens multiple times
|
||||
|
||||
1.3.1 / 2014-10-01
|
||||
==================
|
||||
|
||||
* Fix incorrect 403 on Windows and Node.js 0.11
|
||||
* deps: accepts@~1.1.1
|
||||
- deps: mime-types@~2.0.2
|
||||
- deps: negotiator@0.4.8
|
||||
|
||||
1.3.0 / 2014-09-20
|
||||
==================
|
||||
|
||||
* Add icon for mkv files
|
||||
* Lookup icon by mime type for greater icon support
|
||||
|
||||
1.2.1 / 2014-09-05
|
||||
==================
|
||||
|
||||
* deps: accepts@~1.1.0
|
||||
* deps: debug@~2.0.0
|
||||
|
||||
1.2.0 / 2014-08-25
|
||||
==================
|
||||
|
||||
|
||||
14
README.md
14
README.md
@@ -4,7 +4,7 @@
|
||||
[![NPM Downloads][downloads-image]][downloads-url]
|
||||
[![Build Status][travis-image]][travis-url]
|
||||
[![Test Coverage][coveralls-image]][coveralls-url]
|
||||
[![Gittip][gittip-image]][gittip-url]
|
||||
[![Gratipay][gratipay-image]][gratipay-url]
|
||||
|
||||
Serves pages that contain directory listings for a given path.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -117,7 +121,7 @@ are created by/copyright of [FAMFAMFAM](http://www.famfamfam.com/).
|
||||
[travis-url]: https://travis-ci.org/expressjs/serve-index
|
||||
[coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-index.svg?style=flat
|
||||
[coveralls-url]: https://coveralls.io/r/expressjs/serve-index?branch=master
|
||||
[downloads-image]: http://img.shields.io/npm/dm/serve-index.svg?style=flat
|
||||
[downloads-image]: https://img.shields.io/npm/dm/serve-index.svg?style=flat
|
||||
[downloads-url]: https://npmjs.org/package/serve-index
|
||||
[gittip-image]: https://img.shields.io/gittip/dougwilson.svg?style=flat
|
||||
[gittip-url]: https://www.gittip.com/dougwilson/
|
||||
[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat
|
||||
[gratipay-url]: https://www.gratipay.com/dougwilson/
|
||||
|
||||
381
index.js
381
index.js
@@ -1,4 +1,3 @@
|
||||
|
||||
/*!
|
||||
* serve-index
|
||||
* Copyright(c) 2011 Sencha Inc.
|
||||
@@ -15,15 +14,16 @@
|
||||
*/
|
||||
|
||||
var accepts = require('accepts');
|
||||
var createError = require('http-errors');
|
||||
var debug = require('debug')('serve-index');
|
||||
var http = require('http')
|
||||
, fs = require('fs')
|
||||
var fs = require('fs')
|
||||
, path = require('path')
|
||||
, normalize = path.normalize
|
||||
, sep = path.sep
|
||||
, extname = path.extname
|
||||
, join = path.join;
|
||||
var Batch = require('batch');
|
||||
var mime = require('mime-types');
|
||||
var parseUrl = require('parseurl');
|
||||
var resolve = require('path').resolve;
|
||||
|
||||
@@ -78,8 +78,9 @@ exports = module.exports = function serveIndex(root, options){
|
||||
// root required
|
||||
if (!root) throw new TypeError('serveIndex() root path required');
|
||||
|
||||
// resolve root to absolute
|
||||
// resolve root to absolute and normalize
|
||||
root = resolve(root);
|
||||
root = normalize(root + sep);
|
||||
|
||||
var hidden = options.hidden
|
||||
, icons = options.icons
|
||||
@@ -101,21 +102,24 @@ exports = module.exports = function serveIndex(root, options){
|
||||
// parse URLs
|
||||
var url = parseUrl(req);
|
||||
var originalUrl = parseUrl.original(req);
|
||||
var dir = decodeURIComponent(url.pathname);
|
||||
var originalDir = decodeURIComponent(originalUrl.pathname);
|
||||
|
||||
var dir = decodeURIComponent(url.pathname)
|
||||
, path = normalize(join(root, dir))
|
||||
, originalDir = decodeURIComponent(originalUrl.pathname)
|
||||
var showUp = resolve(path) !== root;
|
||||
// join / normalize from root dir
|
||||
var path = normalize(join(root, dir));
|
||||
|
||||
// null byte(s), bad request
|
||||
if (~path.indexOf('\0')) return next(createError(400));
|
||||
|
||||
// malicious path
|
||||
if (path.substr(0, root.length) !== root) {
|
||||
if ((path + sep).substr(0, root.length) !== root) {
|
||||
debug('malicious path "%s"', path);
|
||||
return next(createError(403));
|
||||
}
|
||||
|
||||
// determine ".." display
|
||||
var showUp = normalize(resolve(path) + sep) !== root;
|
||||
|
||||
// check if we have a directory
|
||||
debug('stat "%s"', path);
|
||||
fs.stat(path, function(err, stat){
|
||||
@@ -137,7 +141,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
|
||||
@@ -167,10 +173,10 @@ exports.html = function(req, res, files, next, dir, showUp, icons, path, view, t
|
||||
files.sort(fileSort);
|
||||
if (showUp) files.unshift({ name: '..' });
|
||||
str = str
|
||||
.replace('{style}', style.concat(iconStyle(files, icons)))
|
||||
.replace('{files}', html(files, dir, icons, view))
|
||||
.replace('{directory}', dir)
|
||||
.replace('{linked-path}', htmlPath(dir));
|
||||
.replace(/\{style\}/g, style.concat(iconStyle(files, icons)))
|
||||
.replace(/\{files\}/g, html(files, dir, icons, view))
|
||||
.replace(/\{directory\}/g, dir)
|
||||
.replace(/\{linked-path\}/g, htmlPath(dir));
|
||||
|
||||
var buf = new Buffer(str, 'utf8');
|
||||
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
||||
@@ -207,22 +213,6 @@ exports.plain = function(req, res, files){
|
||||
res.end(buf);
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate an `Error` from the given status `code`
|
||||
* and optional `msg`.
|
||||
*
|
||||
* @param {Number} code
|
||||
* @param {String} msg
|
||||
* @return {Error}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function createError(code, msg) {
|
||||
var err = new Error(msg || http.STATUS_CODES[code]);
|
||||
err.status = code;
|
||||
return err;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sort function for with directories first.
|
||||
*/
|
||||
@@ -244,6 +234,64 @@ function htmlPath(dir) {
|
||||
}).join(' / ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon data for the file name.
|
||||
*/
|
||||
|
||||
function iconLookup(filename) {
|
||||
var ext = extname(filename);
|
||||
|
||||
// try by extension
|
||||
if (icons[ext]) {
|
||||
return {
|
||||
className: 'icon-' + ext.substring(1),
|
||||
fileName: icons[ext]
|
||||
};
|
||||
}
|
||||
|
||||
var mimetype = mime.lookup(ext);
|
||||
|
||||
// default if no mime type
|
||||
if (mimetype === false) {
|
||||
return {
|
||||
className: 'icon-default',
|
||||
fileName: icons.default
|
||||
};
|
||||
}
|
||||
|
||||
// try by mime type
|
||||
if (icons[mimetype]) {
|
||||
return {
|
||||
className: 'icon-' + mimetype.replace('/', '-'),
|
||||
fileName: icons[mimetype]
|
||||
};
|
||||
}
|
||||
|
||||
var suffix = mimetype.split('+')[1];
|
||||
|
||||
if (suffix && icons['+' + suffix]) {
|
||||
return {
|
||||
className: 'icon-' + suffix,
|
||||
fileName: icons['+' + suffix]
|
||||
};
|
||||
}
|
||||
|
||||
var type = mimetype.split('/')[0];
|
||||
|
||||
// try by type only
|
||||
if (icons[type]) {
|
||||
return {
|
||||
className: 'icon-' + type,
|
||||
fileName: icons[type]
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
className: 'icon-default',
|
||||
fileName: icons.default
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Load icon images, return css string.
|
||||
*/
|
||||
@@ -252,7 +300,7 @@ function iconStyle (files, useIcons) {
|
||||
if (!useIcons) return '';
|
||||
var className;
|
||||
var i;
|
||||
var icon;
|
||||
var iconName;
|
||||
var list = [];
|
||||
var rules = {};
|
||||
var selector;
|
||||
@@ -263,26 +311,27 @@ function iconStyle (files, useIcons) {
|
||||
var file = files[i];
|
||||
|
||||
var isDir = '..' == file.name || (file.stat && file.stat.isDirectory());
|
||||
icon = isDir ? icons.folder : icons[extname(file.name)] || icons.default;
|
||||
var icon = isDir
|
||||
? { className: 'icon-directory', fileName: icons.folder }
|
||||
: iconLookup(file.name);
|
||||
var iconName = icon.fileName;
|
||||
|
||||
var ext = extname(file.name);
|
||||
className = 'icon-' + (isDir ? 'directory' : (icons[ext] ? ext.substring(1) : 'default'));
|
||||
selector = '#files .' + className + ' .name';
|
||||
selector = '#files .' + icon.className + ' .name';
|
||||
|
||||
if (!rules[icon]) {
|
||||
rules[icon] = 'background-image: url(data:image/png;base64,' + load(icon) + ');'
|
||||
selectors[icon] = [];
|
||||
list.push(icon);
|
||||
if (!rules[iconName]) {
|
||||
rules[iconName] = 'background-image: url(data:image/png;base64,' + load(iconName) + ');'
|
||||
selectors[iconName] = [];
|
||||
list.push(iconName);
|
||||
}
|
||||
|
||||
if (!~selectors[icon].indexOf(selector)) {
|
||||
selectors[icon].push(selector);
|
||||
if (selectors[iconName].indexOf(selector) === -1) {
|
||||
selectors[iconName].push(selector);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < list.length; i++) {
|
||||
icon = list[i];
|
||||
style += selectors[icon].join(',\n') + ' {\n ' + rules[icon] + '\n}\n';
|
||||
iconName = list[i];
|
||||
style += selectors[iconName].join(',\n') + ' {\n ' + rules[iconName] + '\n}\n';
|
||||
}
|
||||
|
||||
return style;
|
||||
@@ -293,7 +342,7 @@ function iconStyle (files, useIcons) {
|
||||
*/
|
||||
|
||||
function html(files, dir, useIcons, view) {
|
||||
return '<ul id="files" class="view-'+view+'">'
|
||||
return '<ul id="files" class="view-' + view + '">'
|
||||
+ (view == 'details' ? (
|
||||
'<li class="header">'
|
||||
+ '<span class="name">Name</span>'
|
||||
@@ -306,10 +355,21 @@ function html(files, dir, useIcons, view) {
|
||||
, path = dir.split('/').map(function (c) { return encodeURIComponent(c); });
|
||||
|
||||
if (useIcons) {
|
||||
var ext = extname(file.name);
|
||||
ext = isDir ? '.directory' : (icons[ext] ? ext : '.default');
|
||||
classes.push('icon');
|
||||
classes.push('icon-' + ext.substring(1));
|
||||
|
||||
if (isDir) {
|
||||
classes.push('icon-directory');
|
||||
} else {
|
||||
var ext = extname(file.name);
|
||||
var icon = iconLookup(file.name);
|
||||
|
||||
classes.push('icon');
|
||||
classes.push('icon-' + ext.substring(1));
|
||||
|
||||
if (classes.indexOf(icon.className) === -1) {
|
||||
classes.push(icon.className);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
path.push(encodeURIComponent(file.name));
|
||||
@@ -388,11 +448,9 @@ function stat(dir, files, cb) {
|
||||
files.forEach(function(file){
|
||||
batch.push(function(done){
|
||||
fs.stat(join(dir, file), function(err, stat){
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
// pass ENOENT as null stat, not error
|
||||
return done(err);
|
||||
}
|
||||
if (err && err.code !== 'ENOENT') return done(err);
|
||||
|
||||
// pass ENOENT as null stat, not error
|
||||
done(null, stat || null);
|
||||
});
|
||||
});
|
||||
@@ -406,125 +464,112 @@ function stat(dir, files, cb) {
|
||||
*/
|
||||
|
||||
var icons = {
|
||||
'.js': 'page_white_code_red.png'
|
||||
, '.json': 'page_white_code.png'
|
||||
, '.c': 'page_white_c.png'
|
||||
, '.h': 'page_white_h.png'
|
||||
, '.cc': 'page_white_cplusplus.png'
|
||||
, '.php': 'page_white_php.png'
|
||||
, '.rb': 'page_white_ruby.png'
|
||||
, '.erb': 'page_white_ruby.png'
|
||||
, '.cpp': 'page_white_cplusplus.png'
|
||||
, '.as': 'page_white_actionscript.png'
|
||||
, '.cfm': 'page_white_coldfusion.png'
|
||||
, '.cs': 'page_white_csharp.png'
|
||||
, '.java': 'page_white_cup.png'
|
||||
, '.jsp': 'page_white_cup.png'
|
||||
, '.dll': 'page_white_gear.png'
|
||||
, '.ini': 'page_white_gear.png'
|
||||
, '.asp': 'page_white_code.png'
|
||||
, '.aspx': 'page_white_code.png'
|
||||
, '.clj': 'page_white_code.png'
|
||||
, '.css': 'page_white_code.png'
|
||||
, '.sass': 'page_white_code.png'
|
||||
, '.scss': 'page_white_code.png'
|
||||
, '.less': 'page_white_code.png'
|
||||
, '.htm': 'page_white_code.png'
|
||||
, '.html': 'page_white_code.png'
|
||||
, '.xhtml': 'page_white_code.png'
|
||||
, '.lua': 'page_white_code.png'
|
||||
, '.m': 'page_white_code.png'
|
||||
, '.pl': 'page_white_code.png'
|
||||
, '.py': 'page_white_code.png'
|
||||
, '.vb': 'page_white_code.png'
|
||||
, '.vbs': 'page_white_code.png'
|
||||
, '.xml': 'page_white_code.png'
|
||||
, '.yaws': 'page_white_code.png'
|
||||
, '.map': 'map.png'
|
||||
// base icons
|
||||
'default': 'page_white.png',
|
||||
'folder': 'folder.png',
|
||||
|
||||
, '.app': 'application_xp.png'
|
||||
, '.exe': 'application_xp.png'
|
||||
, '.bat': 'application_xp_terminal.png'
|
||||
, '.cgi': 'application_xp_terminal.png'
|
||||
, '.sh': 'application_xp_terminal.png'
|
||||
// generic mime type icons
|
||||
'image': 'image.png',
|
||||
'text': 'page_white_text.png',
|
||||
'video': 'film.png',
|
||||
|
||||
, '.avi': 'film.png'
|
||||
, '.flv': 'film.png'
|
||||
, '.mv4': 'film.png'
|
||||
, '.mov': 'film.png'
|
||||
, '.mp4': 'film.png'
|
||||
, '.mpeg': 'film.png'
|
||||
, '.mpg': 'film.png'
|
||||
, '.ogv': 'film.png'
|
||||
, '.rm': 'film.png'
|
||||
, '.webm': 'film.png'
|
||||
, '.wmv': 'film.png'
|
||||
, '.fnt': 'font.png'
|
||||
, '.otf': 'font.png'
|
||||
, '.ttf': 'font.png'
|
||||
, '.woff': 'font.png'
|
||||
, '.bmp': 'image.png'
|
||||
, '.gif': 'image.png'
|
||||
, '.ico': 'image.png'
|
||||
, '.jpeg': 'image.png'
|
||||
, '.jpg': 'image.png'
|
||||
, '.png': 'image.png'
|
||||
, '.psd': 'page_white_picture.png'
|
||||
, '.xcf': 'page_white_picture.png'
|
||||
, '.pdf': 'page_white_acrobat.png'
|
||||
, '.swf': 'page_white_flash.png'
|
||||
, '.ai': 'page_white_vector.png'
|
||||
, '.eps': 'page_white_vector.png'
|
||||
, '.ps': 'page_white_vector.png'
|
||||
, '.svg': 'page_white_vector.png'
|
||||
// generic mime suffix icons
|
||||
'+json': 'page_white_code.png',
|
||||
'+xml': 'page_white_code.png',
|
||||
'+zip': 'box.png',
|
||||
|
||||
, '.ods': 'page_white_excel.png'
|
||||
, '.xls': 'page_white_excel.png'
|
||||
, '.xlsx': 'page_white_excel.png'
|
||||
, '.odp': 'page_white_powerpoint.png'
|
||||
, '.ppt': 'page_white_powerpoint.png'
|
||||
, '.pptx': 'page_white_powerpoint.png'
|
||||
, '.md': 'page_white_text.png'
|
||||
, '.srt': 'page_white_text.png'
|
||||
, '.txt': 'page_white_text.png'
|
||||
, '.doc': 'page_white_word.png'
|
||||
, '.docx': 'page_white_word.png'
|
||||
, '.odt': 'page_white_word.png'
|
||||
, '.rtf': 'page_white_word.png'
|
||||
// specific mime type icons
|
||||
'application/font-woff': 'font.png',
|
||||
'application/javascript': 'page_white_code_red.png',
|
||||
'application/json': 'page_white_code.png',
|
||||
'application/msword': 'page_white_word.png',
|
||||
'application/pdf': 'page_white_acrobat.png',
|
||||
'application/postscript': 'page_white_vector.png',
|
||||
'application/rtf': 'page_white_word.png',
|
||||
'application/vnd.ms-excel': 'page_white_excel.png',
|
||||
'application/vnd.ms-powerpoint': 'page_white_powerpoint.png',
|
||||
'application/vnd.oasis.opendocument.presentation': 'page_white_powerpoint.png',
|
||||
'application/vnd.oasis.opendocument.spreadsheet': 'page_white_excel.png',
|
||||
'application/vnd.oasis.opendocument.text': 'page_white_word.png',
|
||||
'application/x-7z-compressed': 'box.png',
|
||||
'application/x-sh': 'application_xp_terminal.png',
|
||||
'application/x-font-ttf': 'font.png',
|
||||
'application/x-msaccess': 'page_white_database.png',
|
||||
'application/x-shockwave-flash': 'page_white_flash.png',
|
||||
'application/x-sql': 'page_white_database.png',
|
||||
'application/x-tar': 'box.png',
|
||||
'application/x-xz': 'box.png',
|
||||
'application/xml': 'page_white_code.png',
|
||||
'application/zip': 'box.png',
|
||||
'image/svg+xml': 'page_white_vector.png',
|
||||
'text/css': 'page_white_code.png',
|
||||
'text/html': 'page_white_code.png',
|
||||
'text/less': 'page_white_code.png',
|
||||
|
||||
, '.dmg': 'drive.png'
|
||||
, '.iso': 'cd.png'
|
||||
, '.7z': 'box.png'
|
||||
, '.apk': 'box.png'
|
||||
, '.bz2': 'box.png'
|
||||
, '.cab': 'box.png'
|
||||
, '.deb': 'box.png'
|
||||
, '.gz': 'box.png'
|
||||
, '.jar': 'box.png'
|
||||
, '.lz': 'box.png'
|
||||
, '.lzma': 'box.png'
|
||||
, '.msi': 'box.png'
|
||||
, '.pkg': 'box.png'
|
||||
, '.rar': 'box.png'
|
||||
, '.rpm': 'box.png'
|
||||
, '.tar': 'box.png'
|
||||
, '.tbz2': 'box.png'
|
||||
, '.tgz': 'box.png'
|
||||
, '.tlz': 'box.png'
|
||||
, '.xz': 'box.png'
|
||||
, '.zip': 'box.png'
|
||||
|
||||
, '.accdb': 'page_white_database.png'
|
||||
, '.db': 'page_white_database.png'
|
||||
, '.dbf': 'page_white_database.png'
|
||||
, '.mdb': 'page_white_database.png'
|
||||
, '.pdb': 'page_white_database.png'
|
||||
, '.sql': 'page_white_database.png'
|
||||
|
||||
, '.gam': 'controller.png'
|
||||
, '.rom': 'controller.png'
|
||||
, '.sav': 'controller.png'
|
||||
|
||||
, 'folder': 'folder.png'
|
||||
, 'default': 'page_white.png'
|
||||
// other, extension-specific icons
|
||||
'.accdb': 'page_white_database.png',
|
||||
'.apk': 'box.png',
|
||||
'.app': 'application_xp.png',
|
||||
'.as': 'page_white_actionscript.png',
|
||||
'.asp': 'page_white_code.png',
|
||||
'.aspx': 'page_white_code.png',
|
||||
'.bat': 'application_xp_terminal.png',
|
||||
'.bz2': 'box.png',
|
||||
'.c': 'page_white_c.png',
|
||||
'.cab': 'box.png',
|
||||
'.cfm': 'page_white_coldfusion.png',
|
||||
'.clj': 'page_white_code.png',
|
||||
'.cc': 'page_white_cplusplus.png',
|
||||
'.cgi': 'application_xp_terminal.png',
|
||||
'.cpp': 'page_white_cplusplus.png',
|
||||
'.cs': 'page_white_csharp.png',
|
||||
'.db': 'page_white_database.png',
|
||||
'.dbf': 'page_white_database.png',
|
||||
'.deb': 'box.png',
|
||||
'.dll': 'page_white_gear.png',
|
||||
'.dmg': 'drive.png',
|
||||
'.docx': 'page_white_word.png',
|
||||
'.erb': 'page_white_ruby.png',
|
||||
'.exe': 'application_xp.png',
|
||||
'.fnt': 'font.png',
|
||||
'.gam': 'controller.png',
|
||||
'.gz': 'box.png',
|
||||
'.h': 'page_white_h.png',
|
||||
'.ini': 'page_white_gear.png',
|
||||
'.iso': 'cd.png',
|
||||
'.jar': 'box.png',
|
||||
'.java': 'page_white_cup.png',
|
||||
'.jsp': 'page_white_cup.png',
|
||||
'.lua': 'page_white_code.png',
|
||||
'.lz': 'box.png',
|
||||
'.lzma': 'box.png',
|
||||
'.m': 'page_white_code.png',
|
||||
'.map': 'map.png',
|
||||
'.msi': 'box.png',
|
||||
'.mv4': 'film.png',
|
||||
'.otf': 'font.png',
|
||||
'.pdb': 'page_white_database.png',
|
||||
'.php': 'page_white_php.png',
|
||||
'.pl': 'page_white_code.png',
|
||||
'.pkg': 'box.png',
|
||||
'.pptx': 'page_white_powerpoint.png',
|
||||
'.psd': 'page_white_picture.png',
|
||||
'.py': 'page_white_code.png',
|
||||
'.rar': 'box.png',
|
||||
'.rb': 'page_white_ruby.png',
|
||||
'.rm': 'film.png',
|
||||
'.rom': 'controller.png',
|
||||
'.rpm': 'box.png',
|
||||
'.sass': 'page_white_code.png',
|
||||
'.sav': 'controller.png',
|
||||
'.scss': 'page_white_code.png',
|
||||
'.srt': 'page_white_text.png',
|
||||
'.tbz2': 'box.png',
|
||||
'.tgz': 'box.png',
|
||||
'.tlz': 'box.png',
|
||||
'.vb': 'page_white_code.png',
|
||||
'.vbs': 'page_white_code.png',
|
||||
'.xcf': 'page_white_picture.png',
|
||||
'.xlsx': 'page_white_excel.png',
|
||||
'.yaws': 'page_white_code.png'
|
||||
};
|
||||
|
||||
14
package.json
14
package.json
@@ -1,21 +1,23 @@
|
||||
{
|
||||
"name": "serve-index",
|
||||
"description": "Serve directory listings",
|
||||
"version": "1.2.0",
|
||||
"version": "1.5.0",
|
||||
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
|
||||
"license": "MIT",
|
||||
"repository": "expressjs/serve-index",
|
||||
"dependencies": {
|
||||
"accepts": "~1.0.7",
|
||||
"accepts": "~1.1.2",
|
||||
"batch": "0.5.1",
|
||||
"debug": "1.0.4",
|
||||
"debug": "~2.1.0",
|
||||
"http-errors": "~1.2.7",
|
||||
"mime-types": "~2.0.2",
|
||||
"parseurl": "~1.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"istanbul": "0.3.0",
|
||||
"mocha": "~1.21.1",
|
||||
"istanbul": "0.3.2",
|
||||
"mocha": "~1.21.5",
|
||||
"should": "~4.0.0",
|
||||
"supertest": "~0.13.0"
|
||||
"supertest": "~0.14.0"
|
||||
},
|
||||
"files": [
|
||||
"public/",
|
||||
|
||||
0
test/fixtures/collect/sample
vendored
Normal file
0
test/fixtures/collect/sample
vendored
Normal file
0
test/fixtures/collect/sample.jpg
vendored
Normal file
0
test/fixtures/collect/sample.jpg
vendored
Normal file
0
test/fixtures/collect/sample.mp4
vendored
Normal file
0
test/fixtures/collect/sample.mp4
vendored
Normal file
0
test/fixtures/collect/sample.pdf
vendored
Normal file
0
test/fixtures/collect/sample.pdf
vendored
Normal file
0
test/fixtures/collect/sample.qfx
vendored
Normal file
0
test/fixtures/collect/sample.qfx
vendored
Normal file
0
test/fixtures/collect/sample.rdf
vendored
Normal file
0
test/fixtures/collect/sample.rdf
vendored
Normal file
0
test/fixtures/collect/sample.txt
vendored
Normal file
0
test/fixtures/collect/sample.txt
vendored
Normal file
0
test/fixtures/collect/sample.xlsx
vendored
Normal file
0
test/fixtures/collect/sample.xlsx
vendored
Normal file
@@ -6,6 +6,7 @@
|
||||
</head>
|
||||
<body class="directory">
|
||||
<h1>This is the test template</h1>
|
||||
<h2>directory {directory}</h2>
|
||||
<div id="wrapper">
|
||||
<h1>{linked-path}</h1>
|
||||
{files}
|
||||
|
||||
39
test/test.js
39
test/test.js
@@ -148,6 +148,7 @@ describe('serveIndex(root)', function () {
|
||||
var urls = res.text.split(/<a href="([^"]*)"/).filter(function(s, i){ return i%2; });
|
||||
urls.should.eql([
|
||||
'/%23directory',
|
||||
'/collect',
|
||||
'/g%23%20%253%20o%20%252525%20%2537%20dir',
|
||||
'/users',
|
||||
'/file%20%231.txt',
|
||||
@@ -263,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 () {
|
||||
@@ -270,11 +291,15 @@ describe('serveIndex(root)', function () {
|
||||
var server = createServer(fixtures, {'icons': true})
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.get('/collect')
|
||||
.expect(/data:image\/png/)
|
||||
.expect(/icon-default/)
|
||||
.expect(/icon-directory/)
|
||||
.expect(/icon-image/)
|
||||
.expect(/icon-txt/)
|
||||
.expect(/icon-application-pdf/)
|
||||
.expect(/icon-video/)
|
||||
.expect(/icon-xml/)
|
||||
.expect(200, done)
|
||||
});
|
||||
});
|
||||
@@ -501,6 +526,18 @@ describe('serveIndex(root)', function () {
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200, /ul#files/, done)
|
||||
});
|
||||
|
||||
it('should list directory twice', function (done) {
|
||||
request(server)
|
||||
.get('/users/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(function (res) {
|
||||
var occurances = res.text.match(/directory \/users\//g)
|
||||
if (occurances && occurances.length === 2) return
|
||||
throw new Error('directory not listed twice')
|
||||
})
|
||||
.expect(200, done)
|
||||
});
|
||||
});
|
||||
|
||||
describe('when setting a custom stylesheet', function () {
|
||||
|
||||
Reference in New Issue
Block a user