Compare commits
75 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a399faa180 | ||
|
|
fc6953383f | ||
|
|
45dbe4f219 | ||
|
|
76e3c3af41 | ||
|
|
da37631e2c | ||
|
|
3e09fb26f9 | ||
|
|
0894f8c9ff | ||
|
|
a4f1ef3d5e | ||
|
|
ccbeaebe69 | ||
|
|
bc077cbe29 | ||
|
|
9ecc9a68f9 | ||
|
|
2b7755a28b | ||
|
|
506626c751 | ||
|
|
2349675b98 | ||
|
|
c5a317fb45 | ||
|
|
9284264604 | ||
|
|
c2585e2c16 | ||
|
|
e7d4062773 | ||
|
|
3e32e4ac3d | ||
|
|
69137b760f | ||
|
|
a8205c834a | ||
|
|
d09bb5e774 | ||
|
|
6024e991ca | ||
|
|
f7e0bb551d | ||
|
|
7215f76cca | ||
|
|
c6b63e4666 | ||
|
|
ec31019c9e | ||
|
|
efe0c6fa7d | ||
|
|
d2bebdbd87 | ||
|
|
3048085dc4 | ||
|
|
1c8c8b9a59 | ||
|
|
2bbaaba5cc | ||
|
|
84285a0826 | ||
|
|
11c2b39640 | ||
|
|
98ecd80f57 | ||
|
|
53a7b06bc6 | ||
|
|
4ed20255be | ||
|
|
8201055cba | ||
|
|
af6bec9cc3 | ||
|
|
2932faa568 | ||
|
|
dc54507b68 | ||
|
|
72b08d6395 | ||
|
|
1284ad0a9f | ||
|
|
a275e385c4 | ||
|
|
357452911d | ||
|
|
fb1c509620 | ||
|
|
2e1836e614 | ||
|
|
ed181e36ed | ||
|
|
f99abfe86a | ||
|
|
e9ccd54a5d | ||
|
|
972e4d1ced | ||
|
|
28e28c8352 | ||
|
|
cd7ab38593 | ||
|
|
a8c6d17b08 | ||
|
|
6cb3ab01a0 | ||
|
|
11b27ed4d3 | ||
|
|
5afc181207 | ||
|
|
8195aa5d6a | ||
|
|
fc9db6b56a | ||
|
|
ac1148a50f | ||
|
|
edc865cb7d | ||
|
|
22e7f31395 | ||
|
|
dd48453baa | ||
|
|
26cc6d91c0 | ||
|
|
735de3e4c0 | ||
|
|
3ce952cfd5 | ||
|
|
7820063014 | ||
|
|
5101c6373c | ||
|
|
b326b6dfa4 | ||
|
|
38a1ab69fa | ||
|
|
191f4b10a3 | ||
|
|
a93f8002a9 | ||
|
|
d3025b9744 | ||
|
|
ac6ea7515a | ||
|
|
b95016be37 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
coverage
|
||||
node_modules
|
||||
npm-debug.log
|
||||
package-lock.json
|
||||
|
||||
31
.travis.yml
31
.travis.yml
@@ -3,10 +3,31 @@ node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "1.0"
|
||||
- "1.8"
|
||||
- "2.0"
|
||||
- "2.3"
|
||||
- "2.5"
|
||||
- "3.3"
|
||||
- "4.8"
|
||||
- "5.12"
|
||||
- "6.11"
|
||||
- "7.10"
|
||||
- "8.3"
|
||||
sudo: false
|
||||
script: "npm run-script test-ci"
|
||||
after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls"
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
before_install:
|
||||
# Skip updating shrinkwrap / lock
|
||||
- "npm config set shrinkwrap false"
|
||||
|
||||
# Setup Node.js version-specific dependencies
|
||||
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
|
||||
|
||||
# Update Node.js modules
|
||||
- "test ! -d node_modules || npm prune"
|
||||
- "test ! -d node_modules || npm rebuild"
|
||||
script:
|
||||
# Run test script, depending on istanbul install
|
||||
- "test ! -z $(npm -ps ls istanbul) || npm test"
|
||||
- "test -z $(npm -ps ls istanbul) || npm run-script test-ci"
|
||||
after_script:
|
||||
- "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
|
||||
|
||||
70
HISTORY.md
70
HISTORY.md
@@ -1,3 +1,73 @@
|
||||
1.9.1 / 2017-09-28
|
||||
==================
|
||||
|
||||
* deps: accepts@~1.3.4
|
||||
- deps: mime-types@~2.1.16
|
||||
* deps: debug@2.6.9
|
||||
* deps: http-errors@~1.6.2
|
||||
- deps: depd@1.1.1
|
||||
* deps: mime-types@~2.1.17
|
||||
- Add new mime types
|
||||
- deps: mime-db@~1.30.0
|
||||
* deps: parseurl@~1.3.2
|
||||
- perf: reduce overhead for full URLs
|
||||
- perf: unroll the "fast-path" `RegExp`
|
||||
|
||||
1.9.0 / 2017-05-25
|
||||
==================
|
||||
|
||||
* Set `X-Content-Type-Options: nosniff` header
|
||||
* deps: batch@0.6.1
|
||||
* deps: debug@2.6.8
|
||||
- Allow colors in workers
|
||||
- Deprecated `DEBUG_FD` environment variable set to `3` or higher
|
||||
- Fix `DEBUG_MAX_ARRAY_LENGTH`
|
||||
- Fix error when running under React Native
|
||||
- Use same color for same namespace
|
||||
- deps: ms@2.0.0
|
||||
* deps: http-errors@~1.6.1
|
||||
- Make `message` property enumerable for `HttpError`s
|
||||
- deps: inherits@2.0.3
|
||||
- deps: setprototypeof@1.0.3
|
||||
- deps: statuses@'>= 1.3.1 < 2'
|
||||
* deps: mime-types@~2.1.15
|
||||
- Add new mime types
|
||||
- Add `audio/mp3`
|
||||
|
||||
1.8.0 / 2016-06-17
|
||||
==================
|
||||
|
||||
* Make inline file search case-insensitive
|
||||
* deps: accepts@~1.3.3
|
||||
- deps: mime-types@~2.1.11
|
||||
- deps: negotiator@0.6.1
|
||||
- perf: improve header parsing speed
|
||||
* deps: http-errors@~1.5.0
|
||||
- Use `setprototypeof` module to replace `__proto__` setting
|
||||
- deps: inherits@2.0.1
|
||||
- deps: statuses@'>= 1.3.0 < 2'
|
||||
- perf: enable strict mode
|
||||
* deps: mime-types@~2.1.11
|
||||
- Add new mime types
|
||||
- Update primary extension for `audio/mp4`
|
||||
- deps: mime-db@~1.23.0
|
||||
|
||||
1.7.3 / 2016-01-24
|
||||
==================
|
||||
|
||||
* deps: accepts@~1.2.13
|
||||
- deps: mime-types@~2.1.6
|
||||
* deps: batch@0.5.3
|
||||
- Fix invalid dependency for browserify
|
||||
* deps: escape-html@~1.0.3
|
||||
- perf: enable strict mode
|
||||
- perf: optimize string replacement
|
||||
- perf: use faster string coercion
|
||||
* deps: mime-types@~2.1.9
|
||||
- Add new mime types
|
||||
* deps: parseurl@~1.3.1
|
||||
- perf: enable strict mode
|
||||
|
||||
1.7.2 / 2015-07-30
|
||||
==================
|
||||
|
||||
|
||||
12
README.md
12
README.md
@@ -11,6 +11,10 @@
|
||||
|
||||
## Install
|
||||
|
||||
This is a [Node.js](https://nodejs.org/en/) module available through the
|
||||
[npm registry](https://www.npmjs.com/). Installation is done using the
|
||||
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
|
||||
|
||||
```sh
|
||||
$ npm install serve-index
|
||||
```
|
||||
@@ -123,8 +127,12 @@ 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()
|
||||
// The express.static serves the file contents
|
||||
// The serveIndex is this module serving the directory
|
||||
app.use('/ftp', express.static('public/ftp'), serveIndex('public/ftp', {'icons': true}))
|
||||
|
||||
// Listen
|
||||
app.listen(3000)
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
20
appveyor.yml
20
appveyor.yml
@@ -3,16 +3,28 @@ environment:
|
||||
- nodejs_version: "0.8"
|
||||
- nodejs_version: "0.10"
|
||||
- nodejs_version: "0.12"
|
||||
- nodejs_version: "1.0"
|
||||
- nodejs_version: "1.8"
|
||||
- nodejs_version: "2.0"
|
||||
- nodejs_version: "2.3"
|
||||
- nodejs_version: "2.5"
|
||||
- nodejs_version: "3.3"
|
||||
- nodejs_version: "4.8"
|
||||
- nodejs_version: "5.12"
|
||||
- nodejs_version: "6.11"
|
||||
- nodejs_version: "7.10"
|
||||
- nodejs_version: "8.3"
|
||||
cache:
|
||||
- node_modules
|
||||
install:
|
||||
- ps: Install-Product node $env:nodejs_version
|
||||
- npm config set shrinkwrap false
|
||||
- if "%nodejs_version%" equ "0.8" npm rm --save-dev istanbul
|
||||
- if exist node_modules npm prune
|
||||
- if exist node_modules npm rebuild
|
||||
- npm install
|
||||
build: off
|
||||
test_script:
|
||||
- node --version
|
||||
- npm --version
|
||||
- npm run test-ci
|
||||
- set npm_test_command=test
|
||||
- for /f %%l in ('npm -ps ls istanbul') do set npm_test_command=test-ci
|
||||
- npm run %npm_test_command%
|
||||
version: "{build}"
|
||||
|
||||
39
index.js
39
index.js
@@ -208,11 +208,7 @@ serveIndex.html = function _html(req, res, files, next, dir, showUp, icons, path
|
||||
// render html
|
||||
render(locals, function (err, body) {
|
||||
if (err) return next(err);
|
||||
|
||||
var buf = new Buffer(body, 'utf8');
|
||||
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
||||
res.setHeader('Content-Length', buf.length);
|
||||
res.end(buf);
|
||||
send(res, 'text/html', body)
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -223,12 +219,7 @@ serveIndex.html = function _html(req, res, files, next, dir, showUp, icons, path
|
||||
*/
|
||||
|
||||
serveIndex.json = function _json(req, res, 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);
|
||||
send(res, 'application/json', JSON.stringify(files))
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -236,12 +227,7 @@ serveIndex.json = function _json(req, res, files) {
|
||||
*/
|
||||
|
||||
serveIndex.plain = function _plain(req, res, files) {
|
||||
var body = files.join('\n') + '\n';
|
||||
var buf = new Buffer(body, 'utf8');
|
||||
|
||||
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
||||
res.setHeader('Content-Length', buf.length);
|
||||
res.end(buf);
|
||||
send(res, 'text/plain', (files.join('\n') + '\n'))
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -425,9 +411,7 @@ function iconLookup(filename) {
|
||||
|
||||
function iconStyle(files, useIcons) {
|
||||
if (!useIcons) return '';
|
||||
var className;
|
||||
var i;
|
||||
var iconName;
|
||||
var list = [];
|
||||
var rules = {};
|
||||
var selector;
|
||||
@@ -505,6 +489,23 @@ function removeHidden(files) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a response.
|
||||
* @private
|
||||
*/
|
||||
|
||||
function send (res, type, body) {
|
||||
// security header for content sniffing
|
||||
res.setHeader('X-Content-Type-Options', 'nosniff')
|
||||
|
||||
// standard headers
|
||||
res.setHeader('Content-Type', type + '; charset=utf-8')
|
||||
res.setHeader('Content-Length', Buffer.byteLength(body, 'utf8'))
|
||||
|
||||
// body
|
||||
res.end(body, 'utf8')
|
||||
}
|
||||
|
||||
/**
|
||||
* Stat all files and return array of stat
|
||||
* in same order.
|
||||
|
||||
24
package.json
24
package.json
@@ -1,24 +1,24 @@
|
||||
{
|
||||
"name": "serve-index",
|
||||
"description": "Serve directory listings",
|
||||
"version": "1.7.2",
|
||||
"version": "1.9.1",
|
||||
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
|
||||
"license": "MIT",
|
||||
"repository": "expressjs/serve-index",
|
||||
"dependencies": {
|
||||
"accepts": "~1.2.12",
|
||||
"batch": "0.5.2",
|
||||
"debug": "~2.2.0",
|
||||
"escape-html": "1.0.2",
|
||||
"http-errors": "~1.3.1",
|
||||
"mime-types": "~2.1.4",
|
||||
"parseurl": "~1.3.0"
|
||||
"accepts": "~1.3.4",
|
||||
"batch": "0.6.1",
|
||||
"debug": "2.6.9",
|
||||
"escape-html": "~1.0.3",
|
||||
"http-errors": "~1.6.2",
|
||||
"mime-types": "~2.1.17",
|
||||
"parseurl": "~1.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"after": "0.8.1",
|
||||
"istanbul": "0.3.9",
|
||||
"mocha": "2.2.5",
|
||||
"supertest": "1.0.1"
|
||||
"after": "0.8.2",
|
||||
"istanbul": "0.4.5",
|
||||
"mocha": "2.5.3",
|
||||
"supertest": "1.1.0"
|
||||
},
|
||||
"files": [
|
||||
"public/",
|
||||
|
||||
@@ -52,11 +52,11 @@
|
||||
}
|
||||
|
||||
function search() {
|
||||
var str = $('search').value
|
||||
, links = $('files').all('a');
|
||||
var str = $('search').value.toLowerCase();
|
||||
var links = $('files').all('a');
|
||||
|
||||
links.each(function(link){
|
||||
var text = link.textContent;
|
||||
var text = link.textContent.toLowerCase();
|
||||
|
||||
if ('..' == text) return;
|
||||
if (str.length && ~text.indexOf(str)) {
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
|
||||
var bytes = require('bytes');
|
||||
|
||||
exports['default request body'] = function(app){
|
||||
it('should default to {}', function(done){
|
||||
app.request()
|
||||
.post('/')
|
||||
.end(function(res){
|
||||
res.body.should.equal('{}');
|
||||
done();
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
exports['limit body to'] = function(size, type, app){
|
||||
it('should accept a limit option', function(done){
|
||||
app.request()
|
||||
.post('/')
|
||||
.set('Content-Length', bytes(size) + 1)
|
||||
.set('Content-Type', type)
|
||||
.end(function(res){
|
||||
res.should.have.status(413);
|
||||
done();
|
||||
})
|
||||
})
|
||||
}
|
||||
39
test/test.js
39
test/test.js
@@ -26,6 +26,15 @@ describe('serveIndex(root)', function () {
|
||||
.expect(200, done)
|
||||
})
|
||||
|
||||
it('should include security header', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.expect('X-Content-Type-Options', 'nosniff')
|
||||
.expect(200, done)
|
||||
})
|
||||
|
||||
it('should serve a directory index', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
@@ -117,6 +126,16 @@ describe('serveIndex(root)', function () {
|
||||
.expect(/さくら\.txt/)
|
||||
.expect(200, done)
|
||||
});
|
||||
|
||||
it('should include security header', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'application/json')
|
||||
.expect('X-Content-Type-Options', 'nosniff')
|
||||
.expect(200, done)
|
||||
})
|
||||
});
|
||||
|
||||
describe('when Accept: text/html is given', function () {
|
||||
@@ -136,6 +155,16 @@ describe('serveIndex(root)', function () {
|
||||
.end(done);
|
||||
});
|
||||
|
||||
it('should include security header', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'text/html')
|
||||
.expect('X-Content-Type-Options', 'nosniff')
|
||||
.expect(200, done)
|
||||
})
|
||||
|
||||
it('should property escape file names', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
@@ -194,6 +223,16 @@ describe('serveIndex(root)', function () {
|
||||
.expect(/さくら\.txt/)
|
||||
.end(done);
|
||||
});
|
||||
|
||||
it('should include security header', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'text/plain')
|
||||
.expect('X-Content-Type-Options', 'nosniff')
|
||||
.expect(200, done)
|
||||
})
|
||||
});
|
||||
|
||||
describe('when Accept: application/x-bogus is given', function () {
|
||||
|
||||
Reference in New Issue
Block a user