Compare commits
94 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
803e4154b2 | ||
|
|
267913151b | ||
|
|
b1e36ccbf5 | ||
|
|
55e914660b | ||
|
|
0ff43c75a8 | ||
|
|
d15b5f1387 | ||
|
|
d5a4b93449 | ||
|
|
244f8a5541 | ||
|
|
ed11812d3f | ||
|
|
4881fb27da | ||
|
|
07e47b1e78 | ||
|
|
55a5939596 | ||
|
|
12d7cb4a7d | ||
|
|
c602a95d4c | ||
|
|
bf15ad0e12 | ||
|
|
9a77df8c77 | ||
|
|
856450da8f | ||
|
|
1bda9f95e4 | ||
|
|
f0652de409 | ||
|
|
f0579f7093 | ||
|
|
970b567f48 | ||
|
|
47b3884bbe | ||
|
|
5b2ff74554 | ||
|
|
7dc0ff4d97 | ||
|
|
1bdd53c05d | ||
|
|
dce12186f8 | ||
|
|
838ee4cc02 | ||
|
|
f332e6e576 | ||
|
|
b866f9690a | ||
|
|
ac94303941 | ||
|
|
cececc8c2e | ||
|
|
5e050a7d23 | ||
|
|
5731ebee6b | ||
|
|
c6b9d3bdbf | ||
|
|
4686c18e1d | ||
|
|
8a06bb7e19 | ||
|
|
effbe1a4b0 | ||
|
|
351c226736 | ||
|
|
1b098fb723 | ||
|
|
8880a8b80a | ||
|
|
276b52782a | ||
|
|
591fd9ca13 | ||
|
|
857b37aad4 | ||
|
|
40a38e688d | ||
|
|
874d32748b | ||
|
|
63456cccf2 | ||
|
|
6ce2fd216b | ||
|
|
83de752968 | ||
|
|
86db218bdb | ||
|
|
0375dd3638 | ||
|
|
005dbad307 | ||
|
|
a189d6b5e5 | ||
|
|
a01c0286df | ||
|
|
6e4da1e8d6 | ||
|
|
d88117fad9 | ||
|
|
194663a06f | ||
|
|
fd277c695c | ||
|
|
ea7b37f19b | ||
|
|
d613373f78 | ||
|
|
afb181df84 | ||
|
|
a70edf46cd | ||
|
|
9ccd58738b | ||
|
|
db905a6d8a | ||
|
|
eeda184dbd | ||
|
|
a879aee5e5 | ||
|
|
7ba4f7cf44 | ||
|
|
a73d752247 | ||
|
|
4e8cf53ce5 | ||
|
|
4e8726c41c | ||
|
|
d7d661245e | ||
|
|
5037f808c0 | ||
|
|
910923b920 | ||
|
|
70c35f62b2 | ||
|
|
73ceabeb00 | ||
|
|
76daee7400 | ||
|
|
f75c172d72 | ||
|
|
7a2a8d2ecc | ||
|
|
cb38e459ca | ||
|
|
2edcc09345 | ||
|
|
a0415f5df2 | ||
|
|
711194e063 | ||
|
|
4d19115d6b | ||
|
|
c00618fa62 | ||
|
|
db91ccac66 | ||
|
|
926ee987fa | ||
|
|
6277105d11 | ||
|
|
199f5d0205 | ||
|
|
871f4d679e | ||
|
|
6e3f352894 | ||
|
|
9fbc4bf182 | ||
|
|
027f6dcf54 | ||
|
|
f7eb0ae92a | ||
|
|
51e9763c0a | ||
|
|
dd6a4a864a |
64
.gitignore
vendored
64
.gitignore
vendored
@@ -1,65 +1,3 @@
|
||||
# Compiled source #
|
||||
###################
|
||||
*.com
|
||||
*.class
|
||||
*.dll
|
||||
*.exe
|
||||
*.o
|
||||
*.so
|
||||
|
||||
# Packages #
|
||||
############
|
||||
# it's better to unpack these files and commit the raw source
|
||||
# git has its own built in compression methods
|
||||
*.7z
|
||||
*.dmg
|
||||
*.gz
|
||||
*.iso
|
||||
*.jar
|
||||
*.rar
|
||||
*.tar
|
||||
*.zip
|
||||
|
||||
# Logs and databases #
|
||||
######################
|
||||
*.log
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
# OS generated files #
|
||||
######################
|
||||
.DS_Store*
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
# Node.js #
|
||||
###########
|
||||
lib-cov
|
||||
*.seed
|
||||
*.log
|
||||
*.csv
|
||||
*.dat
|
||||
*.out
|
||||
*.pid
|
||||
*.gz
|
||||
|
||||
pids
|
||||
logs
|
||||
results
|
||||
|
||||
coverage
|
||||
node_modules
|
||||
npm-debug.log
|
||||
|
||||
# Git #
|
||||
#######
|
||||
*.orig
|
||||
*.BASE.*
|
||||
*.BACKUP.*
|
||||
*.LOCAL.*
|
||||
*.REMOTE.*
|
||||
|
||||
# Components #
|
||||
##############
|
||||
|
||||
/build
|
||||
/components
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
test
|
||||
@@ -3,3 +3,9 @@ node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
matrix:
|
||||
allow_failures:
|
||||
- node_js: "0.11"
|
||||
fast_finish: true
|
||||
script: "npm run-script test-travis"
|
||||
after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls"
|
||||
|
||||
152
HISTORY.md
Normal file
152
HISTORY.md
Normal file
@@ -0,0 +1,152 @@
|
||||
1.6.0 / 2015-01-01
|
||||
==================
|
||||
|
||||
* Add link to root directory
|
||||
* deps: accepts@~1.2.2
|
||||
- deps: mime-types@~2.0.7
|
||||
- deps: negotiator@0.5.0
|
||||
* deps: batch@0.5.2
|
||||
* deps: debug@~2.1.1
|
||||
* deps: mime-types@~2.0.7
|
||||
- Add new mime types
|
||||
- Fix missing extensions
|
||||
- Fix various invalid MIME type entries
|
||||
- Remove example template MIME types
|
||||
- deps: mime-db@~1.5.0
|
||||
|
||||
1.5.3 / 2014-12-10
|
||||
==================
|
||||
|
||||
* deps: accepts@~1.1.4
|
||||
- deps: mime-types@~2.0.4
|
||||
* deps: http-errors@~1.2.8
|
||||
- Fix stack trace from exported function
|
||||
* deps: mime-types@~2.0.4
|
||||
- Add new mime types
|
||||
- deps: mime-db@~1.3.0
|
||||
|
||||
1.5.2 / 2014-12-03
|
||||
==================
|
||||
|
||||
* Fix icon name background alignment on mobile view
|
||||
|
||||
1.5.1 / 2014-11-22
|
||||
==================
|
||||
|
||||
* deps: accepts@~1.1.3
|
||||
- deps: mime-types@~2.0.3
|
||||
* deps: mime-types@~2.0.3
|
||||
- Add new mime types
|
||||
- deps: mime-db@~1.2.0
|
||||
|
||||
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
|
||||
==================
|
||||
|
||||
* Add `debug` messages
|
||||
* Resolve relative paths at middleware setup
|
||||
|
||||
1.1.6 / 2014-08-10
|
||||
==================
|
||||
|
||||
* Fix URL parsing
|
||||
* deps: parseurl@~1.3.0
|
||||
|
||||
1.1.5 / 2014-07-27
|
||||
==================
|
||||
|
||||
* Fix Content-Length calculation for multi-byte file names
|
||||
* deps: accepts@~1.0.7
|
||||
- deps: negotiator@0.4.7
|
||||
|
||||
1.1.4 / 2014-06-20
|
||||
==================
|
||||
|
||||
* deps: accepts@~1.0.5
|
||||
|
||||
1.1.3 / 2014-06-20
|
||||
==================
|
||||
|
||||
* deps: accepts@~1.0.4
|
||||
- use `mime-types`
|
||||
|
||||
1.1.2 / 2014-06-19
|
||||
==================
|
||||
|
||||
* deps: batch@0.5.1
|
||||
|
||||
1.1.1 / 2014-06-11
|
||||
==================
|
||||
|
||||
* deps: accepts@1.0.3
|
||||
|
||||
1.1.0 / 2014-05-29
|
||||
==================
|
||||
|
||||
* Fix content negotiation when no `Accept` header
|
||||
* Properly support all HTTP methods
|
||||
* Support vanilla node.js http servers
|
||||
* Treat `ENAMETOOLONG` as code 414
|
||||
* Use accepts for negotiation
|
||||
|
||||
1.0.3 / 2014-05-20
|
||||
==================
|
||||
|
||||
* Fix error from non-statable files in HTML view
|
||||
|
||||
1.0.2 / 2014-04-28
|
||||
==================
|
||||
|
||||
* Add `stylesheet` option
|
||||
* deps: negotiator@0.4.3
|
||||
|
||||
1.0.1 / 2014-03-05
|
||||
==================
|
||||
|
||||
* deps: negotiator@0.4.2
|
||||
|
||||
1.0.0 / 2014-03-05
|
||||
==================
|
||||
|
||||
* Genesis from connect
|
||||
127
README.md
Normal file
127
README.md
Normal file
@@ -0,0 +1,127 @@
|
||||
# serve-index
|
||||
|
||||
[![NPM Version][npm-image]][npm-url]
|
||||
[![NPM Downloads][downloads-image]][downloads-url]
|
||||
[![Build Status][travis-image]][travis-url]
|
||||
[![Test Coverage][coveralls-image]][coveralls-url]
|
||||
[![Gratipay][gratipay-image]][gratipay-url]
|
||||
|
||||
Serves pages that contain directory listings for a given path.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install serve-index
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
var serveIndex = require('serve-index')
|
||||
```
|
||||
|
||||
### serveIndex(path, options)
|
||||
|
||||
Returns middlware that serves an index of the directory in the given `path`.
|
||||
|
||||
The `path` is based off the `req.url` value, so a `req.url` of `'/some/dir`
|
||||
with a `path` of `'public'` will look at `'public/some/dir'`. If you are using
|
||||
something like `express`, you can change the URL "base" with `app.use` (see
|
||||
the express example).
|
||||
|
||||
#### Options
|
||||
|
||||
Serve index accepts these properties in the options object.
|
||||
|
||||
##### filter
|
||||
|
||||
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
|
||||
|
||||
Display hidden (dot) files. Defaults to `false`.
|
||||
|
||||
##### icons
|
||||
|
||||
Display icons. Defaults to `false`.
|
||||
|
||||
##### stylesheet
|
||||
|
||||
Optional path to a CSS stylesheet. Defaults to a built-in stylesheet.
|
||||
|
||||
##### template
|
||||
|
||||
Optional path to an HTML template. Defaults to a built-in template.
|
||||
|
||||
The following tokens are replaced in templates:
|
||||
|
||||
* `{directory}` with the name of the directory.
|
||||
* `{files}` with the HTML of an unordered list of file links.
|
||||
* `{linked-path}` with the HTML of a link to the directory.
|
||||
* `{style}` with the specified stylesheet and embedded images.
|
||||
|
||||
##### view
|
||||
|
||||
Display mode. `tiles` and `details` are available. Defaults to `tiles`.
|
||||
|
||||
## Examples
|
||||
|
||||
### Serve directory indexes with vanilla node.js http server
|
||||
|
||||
```js
|
||||
var finalhandler = require('finalhandler')
|
||||
var http = require('http')
|
||||
var serveIndex = require('serve-index')
|
||||
var serveStatic = require('serve-static')
|
||||
|
||||
// Serve directory indexes for public/ftp folder (with icons)
|
||||
var index = serveIndex('public/ftp', {'icons': true})
|
||||
|
||||
// Serve up public/ftp folder files
|
||||
var serve = serveStatic('public/ftp')
|
||||
|
||||
// Create server
|
||||
var server = http.createServer(function onRequest(req, res){
|
||||
var done = finalhandler(req, res)
|
||||
serve(req, res, function onNext(err) {
|
||||
if (err) return done(err)
|
||||
index(req, res, done)
|
||||
})
|
||||
})
|
||||
|
||||
// Listen
|
||||
server.listen(3000)
|
||||
```
|
||||
|
||||
### Serve directory indexes with express
|
||||
|
||||
```js
|
||||
var express = require('express')
|
||||
var serveIndex = require('serve-index')
|
||||
|
||||
var app = express()
|
||||
|
||||
// Serve URLs like /ftp/thing as public/ftp/thing
|
||||
app.use('/ftp', serveIndex('public/ftp', {'icons': true}))
|
||||
app.listen()
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE). The [Silk](http://www.famfamfam.com/lab/icons/silk/) icons
|
||||
are created by/copyright of [FAMFAMFAM](http://www.famfamfam.com/).
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/serve-index.svg?style=flat
|
||||
[npm-url]: https://npmjs.org/package/serve-index
|
||||
[travis-image]: https://img.shields.io/travis/expressjs/serve-index.svg?style=flat
|
||||
[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]: https://img.shields.io/npm/dm/serve-index.svg?style=flat
|
||||
[downloads-url]: https://npmjs.org/package/serve-index
|
||||
[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat
|
||||
[gratipay-url]: https://www.gratipay.com/dougwilson/
|
||||
44
Readme.md
44
Readme.md
@@ -1,44 +0,0 @@
|
||||
# Serve Index
|
||||
|
||||
Previously `connect.directory()`.
|
||||
|
||||
[](https://travis-ci.org/expressjs/serve-index)
|
||||
|
||||
Usage:
|
||||
|
||||
```js
|
||||
var connect = require('connect');
|
||||
var serveIndex = require('serve-index');
|
||||
|
||||
var app = connect();
|
||||
|
||||
app.use(serveIndex('public/ftp', {'icons': true}));
|
||||
app.listen();
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Douglas Christopher Wilson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
The [Silk](http://www.famfamfam.com/lab/icons/silk/) icons are created
|
||||
by/copyright of [FAMFAMFAM](http://www.famfamfam.com/).
|
||||
491
index.js
491
index.js
@@ -1,6 +1,5 @@
|
||||
|
||||
/*!
|
||||
* Connect - directory
|
||||
* serve-index
|
||||
* Copyright(c) 2011 Sencha Inc.
|
||||
* Copyright(c) 2011 TJ Holowaychuk
|
||||
* Copyright(c) 2014 Douglas Christopher Wilson
|
||||
@@ -14,16 +13,19 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var http = require('http')
|
||||
, fs = require('fs')
|
||||
, parse = require('url').parse
|
||||
var accepts = require('accepts');
|
||||
var createError = require('http-errors');
|
||||
var debug = require('debug')('serve-index');
|
||||
var fs = require('fs')
|
||||
, path = require('path')
|
||||
, normalize = path.normalize
|
||||
, sep = path.sep
|
||||
, extname = path.extname
|
||||
, join = path.join;
|
||||
var Batch = require('batch');
|
||||
var Negotiator = require('negotiator');
|
||||
var mime = require('mime-types');
|
||||
var parseUrl = require('parseurl');
|
||||
var resolve = require('path').resolve;
|
||||
|
||||
/*!
|
||||
* Icon cache.
|
||||
@@ -60,75 +62,93 @@ var mediaType = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Directory:
|
||||
*
|
||||
* Serve directory listings with the given `root` path.
|
||||
*
|
||||
* Options:
|
||||
* See Readme.md for documentation of options.
|
||||
*
|
||||
* - `hidden` display hidden (dot) files. Defaults to false.
|
||||
* - `view` display mode. 'titles' and 'details' are available. Defaults to titles.
|
||||
* - `icons` display icons. Defaults to false.
|
||||
* - `filter` Apply this filter function to files. Defaults to false.
|
||||
* - `template` Optional path to html template. Defaults to a built-in template.
|
||||
* The following tokens are replaced:
|
||||
* - `{directory}` with the name of the directory.
|
||||
* - `{files}` with the HTML of an unordered list of file links.
|
||||
* - `{linked-path}` with the HTML of a link to the directory.
|
||||
* - `{style}` with the built-in CSS and embedded images.
|
||||
*
|
||||
* @param {String} root
|
||||
* @param {String} path
|
||||
* @param {Object} options
|
||||
* @return {Function}
|
||||
* @return {Function} middleware
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports = module.exports = function directory(root, options){
|
||||
exports = module.exports = function serveIndex(root, options){
|
||||
options = options || {};
|
||||
|
||||
// root required
|
||||
if (!root) throw new Error('directory() root path required');
|
||||
if (!root) throw new TypeError('serveIndex() root path required');
|
||||
|
||||
// resolve root to absolute and normalize
|
||||
root = resolve(root);
|
||||
root = normalize(root + sep);
|
||||
|
||||
var hidden = options.hidden
|
||||
, icons = options.icons
|
||||
, view = options.view || 'tiles'
|
||||
, filter = options.filter
|
||||
, root = normalize(root + sep)
|
||||
, template = options.template || defaultTemplate
|
||||
, stylesheet = options.stylesheet || defaultStylesheet;
|
||||
|
||||
return function directory(req, res, next) {
|
||||
if ('GET' != req.method && 'HEAD' != req.method) return next();
|
||||
return function serveIndex(req, res, next) {
|
||||
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
||||
res.statusCode = 'OPTIONS' === req.method
|
||||
? 200
|
||||
: 405;
|
||||
res.setHeader('Allow', 'GET, HEAD, OPTIONS');
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
var url = parse(req.url)
|
||||
, dir = decodeURIComponent(url.pathname)
|
||||
, path = normalize(join(root, dir))
|
||||
, originalUrl = parse(req.originalUrl)
|
||||
, originalDir = decodeURIComponent(originalUrl.pathname)
|
||||
, showUp = path != root;
|
||||
// parse URLs
|
||||
var url = parseUrl(req);
|
||||
var originalUrl = parseUrl.original(req);
|
||||
var dir = decodeURIComponent(url.pathname);
|
||||
var originalDir = decodeURIComponent(originalUrl.pathname);
|
||||
|
||||
// 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, forbidden
|
||||
if (0 != path.indexOf(root)) return next(createError(403));
|
||||
// malicious path
|
||||
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){
|
||||
if (err) return 'ENOENT' == err.code
|
||||
? next()
|
||||
: next(err);
|
||||
if (err && err.code === 'ENOENT') {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (err) {
|
||||
err.status = err.code === 'ENAMETOOLONG'
|
||||
? 414
|
||||
: 500;
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!stat.isDirectory()) return next();
|
||||
|
||||
// fetch files
|
||||
debug('readdir "%s"', path);
|
||||
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
|
||||
var type = new Negotiator(req).preferredMediaType(mediaTypes);
|
||||
var accept = accepts(req);
|
||||
var type = accept.type(mediaTypes);
|
||||
|
||||
// not acceptable
|
||||
if (!type) return next(createError(406));
|
||||
@@ -153,13 +173,15 @@ 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));
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.setHeader('Content-Length', str.length);
|
||||
res.end(str);
|
||||
.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');
|
||||
res.setHeader('Content-Length', buf.length);
|
||||
res.end(buf);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -170,10 +192,12 @@ exports.html = function(req, res, files, next, dir, showUp, icons, path, view, t
|
||||
*/
|
||||
|
||||
exports.json = function(req, res, files){
|
||||
files = JSON.stringify(files);
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.setHeader('Content-Length', files.length);
|
||||
res.end(files);
|
||||
var body = JSON.stringify(files);
|
||||
var buf = new Buffer(body, 'utf8');
|
||||
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
||||
res.setHeader('Content-Length', buf.length);
|
||||
res.end(buf);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -181,26 +205,12 @@ exports.json = function(req, res, files){
|
||||
*/
|
||||
|
||||
exports.plain = function(req, res, files){
|
||||
files = files.join('\n') + '\n';
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
res.setHeader('Content-Length', files.length);
|
||||
res.end(files);
|
||||
};
|
||||
var body = files.join('\n') + '\n';
|
||||
var buf = new Buffer(body, 'utf8');
|
||||
|
||||
/**
|
||||
* 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;
|
||||
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
||||
res.setHeader('Content-Length', buf.length);
|
||||
res.end(buf);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -224,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.
|
||||
*/
|
||||
@@ -232,7 +300,7 @@ function iconStyle (files, useIcons) {
|
||||
if (!useIcons) return '';
|
||||
var className;
|
||||
var i;
|
||||
var icon;
|
||||
var iconName;
|
||||
var list = [];
|
||||
var rules = {};
|
||||
var selector;
|
||||
@@ -243,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;
|
||||
@@ -273,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>'
|
||||
@@ -286,17 +355,31 @@ 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));
|
||||
|
||||
var date = file.name == '..' ? ''
|
||||
: file.stat.mtime.toDateString()+' '+file.stat.mtime.toLocaleTimeString();
|
||||
var size = isDir ? '' : file.stat.size;
|
||||
var date = file.stat && file.name !== '..'
|
||||
? file.stat.mtime.toDateString() + ' ' + file.stat.mtime.toLocaleTimeString()
|
||||
: '';
|
||||
var size = file.stat && !isDir
|
||||
? file.stat.size
|
||||
: '';
|
||||
|
||||
return '<li><a href="'
|
||||
+ normalizeSlashes(normalize(path.join('/')))
|
||||
@@ -364,7 +447,12 @@ function stat(dir, files, cb) {
|
||||
|
||||
files.forEach(function(file){
|
||||
batch.push(function(done){
|
||||
fs.stat(join(dir, file), done);
|
||||
fs.stat(join(dir, file), function(err, stat){
|
||||
if (err && err.code !== 'ENOENT') return done(err);
|
||||
|
||||
// pass ENOENT as null stat, not error
|
||||
done(null, stat || null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -376,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'
|
||||
};
|
||||
|
||||
36
package.json
36
package.json
@@ -1,30 +1,36 @@
|
||||
{
|
||||
"name": "serve-index",
|
||||
"description": "Serve directory listings",
|
||||
"version": "1.0.2",
|
||||
"version": "1.6.0",
|
||||
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/expressjs/serve-index.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/expressjs/serve-index/issues"
|
||||
},
|
||||
"repository": "expressjs/serve-index",
|
||||
"dependencies": {
|
||||
"batch": "0.5.0",
|
||||
"negotiator": "0.4.3"
|
||||
"accepts": "~1.2.2",
|
||||
"batch": "0.5.2",
|
||||
"debug": "~2.1.1",
|
||||
"http-errors": "~1.2.8",
|
||||
"mime-types": "~2.0.7",
|
||||
"parseurl": "~1.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"connect": "~2.14.1",
|
||||
"mocha": "~1.17.1",
|
||||
"should": "~3.1.3",
|
||||
"supertest": "~0.9.0"
|
||||
"after": "0.8.1",
|
||||
"istanbul": "0.3.5",
|
||||
"mocha": "~2.1.0",
|
||||
"supertest": "~0.15.0"
|
||||
},
|
||||
"files": [
|
||||
"public/",
|
||||
"LICENSE",
|
||||
"HISTORY.md",
|
||||
"index.js"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --reporter spec --require should"
|
||||
"test": "mocha --reporter spec --bail --check-leaks test/",
|
||||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
|
||||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
<body class="directory">
|
||||
<input id="search" type="text" placeholder="Search" autocomplete="off" />
|
||||
<div id="wrapper">
|
||||
<h1>{linked-path}</h1>
|
||||
<h1><a href="/">~</a>{linked-path}</h1>
|
||||
{files}
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -249,7 +249,7 @@ ul#files.view-details li.header {
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
text-indent: 0;
|
||||
background-position: 0 0;
|
||||
background-position: 0 50%;
|
||||
}
|
||||
#files .icon .name {
|
||||
text-indent: 41px;
|
||||
|
||||
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
0
test/fixtures/さくら.txt
vendored
Normal file
0
test/fixtures/さくら.txt
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}
|
||||
|
||||
535
test/test.js
535
test/test.js
@@ -1,70 +1,163 @@
|
||||
|
||||
process.env.NODE_ENV = 'test';
|
||||
|
||||
var connect = require('connect');
|
||||
var after = require('after');
|
||||
var assert = require('assert');
|
||||
var http = require('http');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var request = require('supertest');
|
||||
var serveIndex = require('..');
|
||||
|
||||
describe('directory()', function(){
|
||||
describe('when given Accept: header', function () {
|
||||
var server;
|
||||
before(function () {
|
||||
server = createServer();
|
||||
});
|
||||
after(function (done) {
|
||||
server.close(done);
|
||||
});
|
||||
var fixtures = path.join(__dirname, '/fixtures');
|
||||
var relative = path.relative(process.cwd(), fixtures);
|
||||
|
||||
describe('of application/json', function () {
|
||||
var skipRelative = ~relative.indexOf('..') || path.resolve(relative) === relative;
|
||||
|
||||
describe('serveIndex(root)', function () {
|
||||
it('should require root', function () {
|
||||
assert.throws(serveIndex, /root path required/)
|
||||
})
|
||||
|
||||
it('should serve text/html without Accept header', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.expect('Content-Type', 'text/html; charset=utf-8')
|
||||
.expect(200, done)
|
||||
})
|
||||
|
||||
it('should serve a directory index', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.expect(200, /todo\.txt/, done)
|
||||
})
|
||||
|
||||
it('should work with HEAD requests', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.head('/')
|
||||
.expect(200, '', done)
|
||||
})
|
||||
|
||||
it('should work with OPTIONS requests', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.options('/')
|
||||
.expect('Allow', 'GET, HEAD, OPTIONS')
|
||||
.expect(200, done)
|
||||
})
|
||||
|
||||
it('should deny POST requests', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.post('/')
|
||||
.expect(405, done)
|
||||
})
|
||||
|
||||
it('should deny path will NULL byte', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/%00')
|
||||
.expect(400, done)
|
||||
})
|
||||
|
||||
it('should deny path outside root', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/../')
|
||||
.expect(403, done)
|
||||
})
|
||||
|
||||
it('should skip non-existent paths', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/bogus')
|
||||
.expect(404, 'Not Found', done)
|
||||
})
|
||||
|
||||
it('should treat an ENAMETOOLONG as a 414', function (done) {
|
||||
var path = Array(11000).join('foobar')
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/' + path)
|
||||
.expect(414, done)
|
||||
})
|
||||
|
||||
it('should skip non-directories', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/nums')
|
||||
.expect(404, 'Not Found', done)
|
||||
})
|
||||
|
||||
describe('when given Accept: header', function () {
|
||||
describe('when Accept: application/json is given', function () {
|
||||
it('should respond with json', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.end(function (err, res) {
|
||||
if (err) throw err;
|
||||
res.body.should.include('g# %3 o %2525 %37 dir');
|
||||
res.body.should.include('users');
|
||||
res.body.should.include('file #1.txt');
|
||||
res.body.should.include('nums');
|
||||
res.body.should.include('todo.txt');
|
||||
done();
|
||||
});
|
||||
.expect(/g# %3 o %2525 %37 dir/)
|
||||
.expect(/users/)
|
||||
.expect(/file #1\.txt/)
|
||||
.expect(/nums/)
|
||||
.expect(/todo\.txt/)
|
||||
.expect(/さくら\.txt/)
|
||||
.expect(200, done)
|
||||
});
|
||||
});
|
||||
|
||||
describe('when Accept: text/html is given', function () {
|
||||
it('should respond with html', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /html/)
|
||||
.expect('Content-Type', 'text/html; charset=utf-8')
|
||||
.expect(/<a href="\/g%23%20%253%20o%20%252525%20%2537%20dir"/)
|
||||
.expect(/<a href="\/users"/)
|
||||
.expect(/<a href="\/file%20%231.txt"/)
|
||||
.expect(/<a href="\/todo.txt"/)
|
||||
.expect(/<a href="\/%E3%81%95%E3%81%8F%E3%82%89\.txt"/)
|
||||
.end(done);
|
||||
});
|
||||
|
||||
it('should sort folders first', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /html/)
|
||||
.expect('Content-Type', 'text/html; charset=utf-8')
|
||||
.end(function (err, res) {
|
||||
if (err) throw err;
|
||||
var urls = res.text.split(/<a href="([^"]*)"/).filter(function(s, i){ return i%2; });
|
||||
urls.should.eql([
|
||||
if (err) done(err);
|
||||
var body = res.text.split('</h1>')[1];
|
||||
var urls = body.split(/<a href="([^"]*)"/).filter(function(s, i){ return i%2; });
|
||||
assert.deepEqual(urls, [
|
||||
'/%23directory',
|
||||
'/collect',
|
||||
'/g%23%20%253%20o%20%252525%20%2537%20dir',
|
||||
'/users',
|
||||
'/file%20%231.txt',
|
||||
'/foo%20bar',
|
||||
'/nums',
|
||||
'/todo.txt',
|
||||
'/%E3%81%95%E3%81%8F%E3%82%89.txt'
|
||||
]);
|
||||
done();
|
||||
});
|
||||
@@ -73,63 +166,306 @@ describe('directory()', function(){
|
||||
|
||||
describe('when Accept: text/plain is given', function () {
|
||||
it('should respond with text', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'text/plain')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /plain/)
|
||||
.expect('Content-Type', 'text/plain; charset=utf-8')
|
||||
.expect(/users/)
|
||||
.expect(/g# %3 o %2525 %37 dir/)
|
||||
.expect(/file #1.txt/)
|
||||
.expect(/todo.txt/)
|
||||
.expect(/さくら\.txt/)
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when Accept: application/x-bogus is given', function () {
|
||||
it('should respond with 406', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'application/x-bogus')
|
||||
.expect(406, done)
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with "hidden" option', function () {
|
||||
it('should filter hidden files by default', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.expect(bodyDoesNotContain('.hidden'))
|
||||
.expect(200, done)
|
||||
});
|
||||
|
||||
it('should filter hidden files', function (done) {
|
||||
var server = createServer('test/fixtures', {'hidden': false})
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.expect(bodyDoesNotContain('.hidden'))
|
||||
.expect(200, done)
|
||||
});
|
||||
|
||||
it('should not filter hidden files', function (done) {
|
||||
var server = createServer('test/fixtures', {'hidden': true})
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.expect(200, /\.hidden/, done)
|
||||
});
|
||||
});
|
||||
|
||||
describe('with "filter" option', function () {
|
||||
it('should custom filter files', function (done) {
|
||||
var cb = after(2, done)
|
||||
var server = createServer(fixtures, {'filter': filter})
|
||||
|
||||
function filter(name) {
|
||||
if (name.indexOf('foo') === -1) return true
|
||||
cb()
|
||||
return false
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.expect(bodyDoesNotContain('foo'))
|
||||
.expect(200, cb)
|
||||
});
|
||||
|
||||
it('should filter after hidden filter', function (done) {
|
||||
var server = createServer(fixtures, {'filter': filter, 'hidden': false})
|
||||
|
||||
function filter(name) {
|
||||
if (name.indexOf('.') === 0) {
|
||||
done(new Error('unexpected hidden file'))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.expect(200, done)
|
||||
});
|
||||
|
||||
it('should filter directory paths', function (done) {
|
||||
var cb = after(3, done)
|
||||
var server = createServer(fixtures, {'filter': filter})
|
||||
|
||||
function filter(name, index, list, dir) {
|
||||
if (path.normalize(dir) === path.normalize(path.join(fixtures, '/users'))) {
|
||||
cb()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/users')
|
||||
.expect(200, cb)
|
||||
});
|
||||
});
|
||||
|
||||
describe('with "icons" option', function () {
|
||||
it('should include icons for html', function (done) {
|
||||
var server = createServer(fixtures, {'icons': true})
|
||||
|
||||
request(server)
|
||||
.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)
|
||||
});
|
||||
});
|
||||
|
||||
describe('when using custom handler', function () {
|
||||
describe('exports.html', function () {
|
||||
alterProperty(serveIndex, 'html', serveIndex.html)
|
||||
|
||||
it('should get called with Accept: text/html', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
serveIndex.html = function (req, res, files) {
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.end('called');
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200, 'called', done)
|
||||
});
|
||||
|
||||
it('should get file list', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
serveIndex.html = function (req, res, files) {
|
||||
var text = files
|
||||
.filter(function (f) { return /\.txt$/.test(f) })
|
||||
.sort()
|
||||
res.setHeader('Content-Type', 'text/html')
|
||||
res.end('<b>' + text.length + ' text files</b>')
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200, '<b>3 text files</b>', done)
|
||||
});
|
||||
|
||||
it('should get dir name', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
serveIndex.html = function (req, res, files, next, dir) {
|
||||
res.setHeader('Content-Type', 'text/html')
|
||||
res.end('<b>' + dir + '</b>')
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/users/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200, '<b>/users/</b>', done)
|
||||
});
|
||||
|
||||
it('should get template path', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
serveIndex.html = function (req, res, files, next, dir, showUp, icons, path, view, template) {
|
||||
res.setHeader('Content-Type', 'text/html')
|
||||
res.end(String(fs.existsSync(template)))
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/users/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200, 'true', done)
|
||||
});
|
||||
|
||||
it('should get template with tokens', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
serveIndex.html = function (req, res, files, next, dir, showUp, icons, path, view, template) {
|
||||
res.setHeader('Content-Type', 'text/html')
|
||||
res.end(fs.readFileSync(template, 'utf8'))
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/users/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(/{directory}/)
|
||||
.expect(/{files}/)
|
||||
.expect(/{linked-path}/)
|
||||
.expect(/{style}/)
|
||||
.expect(200, done)
|
||||
});
|
||||
|
||||
it('should get stylesheet path', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
serveIndex.html = function (req, res, files, next, dir, showUp, icons, path, view, template, stylesheet) {
|
||||
res.setHeader('Content-Type', 'text/html')
|
||||
res.end(String(fs.existsSync(stylesheet)))
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/users/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200, 'true', done)
|
||||
});
|
||||
});
|
||||
|
||||
describe('exports.plain', function () {
|
||||
alterProperty(serveIndex, 'plain', serveIndex.plain)
|
||||
|
||||
it('should get called with Accept: text/plain', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
serveIndex.plain = function (req, res, files) {
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
res.end('called');
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'text/plain')
|
||||
.expect(200, 'called', done)
|
||||
});
|
||||
});
|
||||
|
||||
describe('exports.json', function () {
|
||||
alterProperty(serveIndex, 'json', serveIndex.json)
|
||||
|
||||
it('should get called with Accept: application/json', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
serveIndex.json = function (req, res, files) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end('"called"');
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(200, '"called"', done)
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when navigating to other directory', function () {
|
||||
var server;
|
||||
before(function () {
|
||||
server = createServer();
|
||||
});
|
||||
after(function (done) {
|
||||
server.close(done);
|
||||
});
|
||||
|
||||
it('should respond with correct listing', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/users/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /html/)
|
||||
.expect('Content-Type', 'text/html; charset=utf-8')
|
||||
.expect(/<a href="\/users\/index.html"/)
|
||||
.expect(/<a href="\/users\/tobi.txt"/)
|
||||
.end(done);
|
||||
});
|
||||
|
||||
it('should work for directory with #', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/%23directory/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /html/)
|
||||
.expect('Content-Type', 'text/html; charset=utf-8')
|
||||
.expect(/<a href="\/%23directory"/)
|
||||
.expect(/<a href="\/%23directory\/index.html"/)
|
||||
.end(done);
|
||||
});
|
||||
|
||||
it('should work for directory with special chars', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/g%23%20%253%20o%20%252525%20%2537%20dir/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /html/)
|
||||
.expect('Content-Type', 'text/html; charset=utf-8')
|
||||
.expect(/<a href="\/g%23%20%253%20o%20%252525%20%2537%20dir"/)
|
||||
.expect(/<a href="\/g%23%20%253%20o%20%252525%20%2537%20dir\/empty.txt"/)
|
||||
.end(done);
|
||||
});
|
||||
|
||||
it('should not work for outside root', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/../support/')
|
||||
.set('Accept', 'text/html')
|
||||
@@ -140,34 +476,51 @@ describe('directory()', function(){
|
||||
describe('when setting a custom template', function () {
|
||||
var server;
|
||||
before(function () {
|
||||
server = createServer('test/fixtures', {'template': __dirname + '/shared/template.html'});
|
||||
});
|
||||
after(function (done) {
|
||||
server.close(done);
|
||||
server = createServer(fixtures, {'template': __dirname + '/shared/template.html'});
|
||||
});
|
||||
|
||||
it('should respond with file list and testing template sentence', function (done) {
|
||||
it('should respond with file list', function (done) {
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /html/)
|
||||
.expect(/<a href="\/g%23%20%253%20o%20%252525%20%2537%20dir"/)
|
||||
.expect(/<a href="\/users"/)
|
||||
.expect(/<a href="\/file%20%231.txt"/)
|
||||
.expect(/<a href="\/todo.txt"/)
|
||||
.expect(/This is the test template/)
|
||||
.end(done);
|
||||
.expect(200, done)
|
||||
});
|
||||
|
||||
it('should respond with testing template sentence', function (done) {
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200, /This is the test template/, done)
|
||||
});
|
||||
|
||||
it('should have default styles', function (done) {
|
||||
request(server)
|
||||
.get('/')
|
||||
.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 () {
|
||||
var server;
|
||||
before(function () {
|
||||
server = createServer('test/fixtures', {'stylesheet': __dirname + '/shared/styles.css'});
|
||||
});
|
||||
after(function (done) {
|
||||
server.close(done);
|
||||
server = createServer(fixtures, {'stylesheet': __dirname + '/shared/styles.css'});
|
||||
});
|
||||
|
||||
it('should respond with appropriate embedded styles', function (done) {
|
||||
@@ -175,7 +528,7 @@ describe('directory()', function(){
|
||||
.get('/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /html/)
|
||||
.expect('Content-Type', 'text/html; charset=utf-8')
|
||||
.expect(/color: #00ff00;/)
|
||||
.end(done);
|
||||
});
|
||||
@@ -184,51 +537,39 @@ describe('directory()', function(){
|
||||
describe('when set with trailing slash', function () {
|
||||
var server;
|
||||
before(function () {
|
||||
server = createServer('test/fixtures/');
|
||||
});
|
||||
after(function (done) {
|
||||
server.close(done);
|
||||
server = createServer(fixtures + '/');
|
||||
});
|
||||
|
||||
it('should respond with file list', function (done) {
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.end(function (err, res) {
|
||||
if (err) throw err;
|
||||
res.body.should.include('users');
|
||||
res.body.should.include('file #1.txt');
|
||||
res.body.should.include('nums');
|
||||
res.body.should.include('todo.txt');
|
||||
done();
|
||||
});
|
||||
.expect(/users/)
|
||||
.expect(/file #1\.txt/)
|
||||
.expect(/nums/)
|
||||
.expect(/todo\.txt/)
|
||||
.expect(200, done)
|
||||
});
|
||||
});
|
||||
|
||||
describe('when set to \'.\'', function () {
|
||||
(skipRelative ? describe.skip : describe)('when set to \'.\'', function () {
|
||||
var server;
|
||||
before(function () {
|
||||
server = createServer('.');
|
||||
});
|
||||
after(function (done) {
|
||||
server.close(done);
|
||||
});
|
||||
|
||||
it('should respond with file list', function (done) {
|
||||
var dest = relative.split(path.sep).join('/');
|
||||
request(server)
|
||||
.get('/')
|
||||
.get('/' + dest + '/')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.end(function (err, res) {
|
||||
if (err) throw err;
|
||||
res.body.should.include('LICENSE');
|
||||
res.body.should.include('public');
|
||||
res.body.should.include('test');
|
||||
done();
|
||||
});
|
||||
.expect(/users/)
|
||||
.expect(/file #1\.txt/)
|
||||
.expect(/nums/)
|
||||
.expect(/todo\.txt/)
|
||||
.expect(200, done)
|
||||
});
|
||||
|
||||
it('should not allow serving outside root', function (done) {
|
||||
@@ -240,9 +581,33 @@ describe('directory()', function(){
|
||||
});
|
||||
});
|
||||
|
||||
function createServer(dir, opts) {
|
||||
var app = connect();
|
||||
dir = dir || 'test/fixtures';
|
||||
app.use(serveIndex(dir, opts));
|
||||
return app.listen();
|
||||
function alterProperty(obj, prop, val) {
|
||||
var prev
|
||||
|
||||
beforeEach(function () {
|
||||
prev = obj[prop]
|
||||
obj[prop] = val
|
||||
})
|
||||
afterEach(function () {
|
||||
obj[prop] = prev
|
||||
})
|
||||
}
|
||||
|
||||
function createServer(dir, opts) {
|
||||
dir = dir || fixtures
|
||||
|
||||
var _serveIndex = serveIndex(dir, opts)
|
||||
|
||||
return http.createServer(function (req, res) {
|
||||
_serveIndex(req, res, function (err) {
|
||||
res.statusCode = err ? (err.status || 500) : 404
|
||||
res.end(err ? err.message : 'Not Found')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function bodyDoesNotContain(text) {
|
||||
return function (res) {
|
||||
assert.equal(res.text.indexOf(text), -1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user