Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bdab07acf | ||
|
|
a6f02f060d | ||
|
|
90252c37b9 | ||
|
|
94fcb7092e | ||
|
|
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 |
@@ -7,5 +7,5 @@ matrix:
|
||||
allow_failures:
|
||||
- node_js: "0.11"
|
||||
fast_finish: true
|
||||
script: "npm run-script test-travis"
|
||||
script: "npm run-script test-ci"
|
||||
after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls"
|
||||
|
||||
59
HISTORY.md
59
HISTORY.md
@@ -1,3 +1,62 @@
|
||||
1.6.1 / 2015-01-31
|
||||
==================
|
||||
|
||||
* deps: accepts@~1.2.3
|
||||
- deps: mime-types@~2.0.8
|
||||
* deps: mime-types@~2.0.8
|
||||
- Add new mime types
|
||||
- deps: mime-db@~1.6.0
|
||||
|
||||
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
|
||||
==================
|
||||
|
||||
|
||||
15
README.md
15
README.md
@@ -2,9 +2,10 @@
|
||||
|
||||
[![NPM Version][npm-image]][npm-url]
|
||||
[![NPM Downloads][downloads-image]][downloads-url]
|
||||
[![Build Status][travis-image]][travis-url]
|
||||
[![Linux Build][travis-image]][travis-url]
|
||||
[![Windows Build][appveyor-image]][appveyor-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.
|
||||
|
||||
@@ -117,11 +118,13 @@ 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-image]: https://img.shields.io/travis/expressjs/serve-index/master.svg?label=linux&style=flat
|
||||
[travis-url]: https://travis-ci.org/expressjs/serve-index
|
||||
[coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-index.svg?style=flat
|
||||
[appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/serve-index/master.svg?label=windows&style=flat
|
||||
[appveyor-url]: https://ci.appveyor.com/project/dougwilson/serve-index
|
||||
[coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-index/master.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
|
||||
[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/
|
||||
|
||||
18
appveyor.yml
Normal file
18
appveyor.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
environment:
|
||||
matrix:
|
||||
- nodejs_version: "0.8"
|
||||
- nodejs_version: "0.10"
|
||||
- nodejs_version: "0.11"
|
||||
matrix:
|
||||
allow_failures:
|
||||
- nodejs_version: "0.11"
|
||||
fast_finish: true
|
||||
install:
|
||||
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version)
|
||||
- npm install
|
||||
build: off
|
||||
test_script:
|
||||
- node --version
|
||||
- npm --version
|
||||
- npm run test-ci
|
||||
version: "{build}"
|
||||
23
index.js
23
index.js
@@ -1,4 +1,3 @@
|
||||
|
||||
/*!
|
||||
* serve-index
|
||||
* Copyright(c) 2011 Sencha Inc.
|
||||
@@ -15,9 +14,9 @@
|
||||
*/
|
||||
|
||||
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
|
||||
@@ -149,7 +148,7 @@ exports = module.exports = function serveIndex(root, options){
|
||||
|
||||
// content-negotiation
|
||||
var accept = accepts(req);
|
||||
var type = accept.types(mediaTypes);
|
||||
var type = accept.type(mediaTypes);
|
||||
|
||||
// not acceptable
|
||||
if (!type) return next(createError(406));
|
||||
@@ -214,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.
|
||||
*/
|
||||
|
||||
23
package.json
23
package.json
@@ -1,22 +1,23 @@
|
||||
{
|
||||
"name": "serve-index",
|
||||
"description": "Serve directory listings",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.1",
|
||||
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
|
||||
"license": "MIT",
|
||||
"repository": "expressjs/serve-index",
|
||||
"dependencies": {
|
||||
"accepts": "~1.1.2",
|
||||
"batch": "0.5.1",
|
||||
"debug": "~2.0.0",
|
||||
"mime-types": "~2.0.1",
|
||||
"accepts": "~1.2.3",
|
||||
"batch": "0.5.2",
|
||||
"debug": "~2.1.1",
|
||||
"http-errors": "~1.2.8",
|
||||
"mime-types": "~2.0.8",
|
||||
"parseurl": "~1.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"istanbul": "0.3.2",
|
||||
"mocha": "~1.21.5",
|
||||
"should": "~4.0.0",
|
||||
"supertest": "~0.14.0"
|
||||
"after": "0.8.1",
|
||||
"istanbul": "0.3.5",
|
||||
"mocha": "~2.1.0",
|
||||
"supertest": "~0.15.0"
|
||||
},
|
||||
"files": [
|
||||
"public/",
|
||||
@@ -29,7 +30,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"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/"
|
||||
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
|
||||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --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;
|
||||
|
||||
93
test/test.js
93
test/test.js
@@ -1,9 +1,10 @@
|
||||
|
||||
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 should = require('should');
|
||||
var serveIndex = require('..');
|
||||
|
||||
var fixtures = path.join(__dirname, '/fixtures');
|
||||
@@ -13,7 +14,7 @@ var skipRelative = ~relative.indexOf('..') || path.resolve(relative) === relativ
|
||||
|
||||
describe('serveIndex(root)', function () {
|
||||
it('should require root', function () {
|
||||
serveIndex.should.throw(/root path required/)
|
||||
assert.throws(serveIndex, /root path required/)
|
||||
})
|
||||
|
||||
it('should serve text/html without Accept header', function (done) {
|
||||
@@ -144,9 +145,10 @@ describe('serveIndex(root)', function () {
|
||||
.expect(200)
|
||||
.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',
|
||||
@@ -198,11 +200,8 @@ describe('serveIndex(root)', function () {
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.expect(200, function (err, res) {
|
||||
if (err) return done(err)
|
||||
res.text.should.not.containEql('.hidden')
|
||||
done()
|
||||
});
|
||||
.expect(bodyDoesNotContain('.hidden'))
|
||||
.expect(200, done)
|
||||
});
|
||||
|
||||
it('should filter hidden files', function (done) {
|
||||
@@ -210,11 +209,8 @@ describe('serveIndex(root)', function () {
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.expect(200, function (err, res) {
|
||||
if (err) return done(err)
|
||||
res.text.should.not.containEql('.hidden')
|
||||
done()
|
||||
});
|
||||
.expect(bodyDoesNotContain('.hidden'))
|
||||
.expect(200, done)
|
||||
});
|
||||
|
||||
it('should not filter hidden files', function (done) {
|
||||
@@ -228,61 +224,51 @@ describe('serveIndex(root)', function () {
|
||||
|
||||
describe('with "filter" option', function () {
|
||||
it('should custom filter files', function (done) {
|
||||
var seen = false
|
||||
var cb = after(2, done)
|
||||
var server = createServer(fixtures, {'filter': filter})
|
||||
|
||||
function filter(name) {
|
||||
if (name.indexOf('foo') === -1) return true
|
||||
seen = true
|
||||
cb()
|
||||
return false
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.expect(200, function (err, res) {
|
||||
if (err) return done(err)
|
||||
seen.should.be.true
|
||||
res.text.should.not.containEql('foo')
|
||||
done()
|
||||
});
|
||||
.expect(bodyDoesNotContain('foo'))
|
||||
.expect(200, cb)
|
||||
});
|
||||
|
||||
it('should filter after hidden filter', function (done) {
|
||||
var seen = false
|
||||
var server = createServer(fixtures, {'filter': filter, 'hidden': false})
|
||||
|
||||
function filter(name) {
|
||||
seen = seen || name.indexOf('.') === 0
|
||||
if (name.indexOf('.') === 0) {
|
||||
done(new Error('unexpected hidden file'))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.expect(200, function (err, res) {
|
||||
if (err) return done(err)
|
||||
seen.should.be.false
|
||||
done()
|
||||
});
|
||||
.expect(200, done)
|
||||
});
|
||||
|
||||
it('should filter directory paths', function (done) {
|
||||
var seen = false
|
||||
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'))) {
|
||||
seen = true
|
||||
cb()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
request(server)
|
||||
.get('/users')
|
||||
.expect(200, function (err, res) {
|
||||
if (err) return done(err)
|
||||
seen.should.be.true
|
||||
done()
|
||||
});
|
||||
.expect(200, cb)
|
||||
});
|
||||
});
|
||||
|
||||
@@ -306,10 +292,7 @@ describe('serveIndex(root)', function () {
|
||||
|
||||
describe('when using custom handler', function () {
|
||||
describe('exports.html', function () {
|
||||
var orig = serveIndex.html
|
||||
after(function () {
|
||||
serveIndex.html = orig
|
||||
})
|
||||
alterProperty(serveIndex, 'html', serveIndex.html)
|
||||
|
||||
it('should get called with Accept: text/html', function (done) {
|
||||
var server = createServer()
|
||||
@@ -404,10 +387,7 @@ describe('serveIndex(root)', function () {
|
||||
});
|
||||
|
||||
describe('exports.plain', function () {
|
||||
var orig = serveIndex.plain
|
||||
after(function () {
|
||||
serveIndex.plain = orig
|
||||
})
|
||||
alterProperty(serveIndex, 'plain', serveIndex.plain)
|
||||
|
||||
it('should get called with Accept: text/plain', function (done) {
|
||||
var server = createServer()
|
||||
@@ -425,10 +405,7 @@ describe('serveIndex(root)', function () {
|
||||
});
|
||||
|
||||
describe('exports.json', function () {
|
||||
var orig = serveIndex.json
|
||||
after(function () {
|
||||
serveIndex.json = orig
|
||||
})
|
||||
alterProperty(serveIndex, 'json', serveIndex.json)
|
||||
|
||||
it('should get called with Accept: application/json', function (done) {
|
||||
var server = createServer()
|
||||
@@ -604,6 +581,18 @@ describe('serveIndex(root)', function () {
|
||||
});
|
||||
});
|
||||
|
||||
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
|
||||
|
||||
@@ -616,3 +605,9 @@ function createServer(dir, opts) {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function bodyDoesNotContain(text) {
|
||||
return function (res) {
|
||||
assert.equal(res.text.indexOf(text), -1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user