Compare commits

..

12 Commits

Author SHA1 Message Date
Douglas Christopher Wilson
cff5890bce 1.0.2 2014-04-28 14:44:13 -04:00
Douglas Christopher Wilson
6d9e23c5ac docs: use SVG Travis CI badge 2014-04-28 14:34:00 -04:00
Douglas Christopher Wilson
36d68485ab deps: negotiator@0.4.3 2014-04-28 14:32:38 -04:00
Chris O'Connor
e40300aa86 Add stylesheet option
closes #2
2014-04-28 14:31:00 -04:00
Anthony Verez
5771318d78 docs: document the view option
closes #1
2014-04-26 13:16:02 -04:00
Douglas Christopher Wilson
d006e3a123 deps: tighten devDepencency ranges 2014-03-06 14:51:51 -05:00
Douglas Christopher Wilson
a2364a8abf test: test on node.js 0.11 2014-03-06 13:26:46 -05:00
Douglas Christopher Wilson
90e39a9a4f deps: use 0.8-compatible semver in devDependencies 2014-03-06 13:23:48 -05:00
Douglas Christopher Wilson
480fdcc468 docs: add Travis CI badge 2014-03-06 13:02:48 -05:00
Douglas Christopher Wilson
b4cd08b1a3 1.0.1 2014-03-06 09:59:04 -05:00
Douglas Christopher Wilson
c1b2ad4a71 deps: negotiator@0.4.2 2014-03-06 09:58:26 -05:00
Douglas Christopher Wilson
e18a68fc94 docs: add note about Silk icons 2014-03-05 22:42:46 -05:00
6 changed files with 40 additions and 9 deletions

View File

@@ -2,3 +2,4 @@ language: node_js
node_js:
- "0.8"
- "0.10"
- "0.11"

View File

@@ -2,6 +2,8 @@
Previously `connect.directory()`.
[![Build Status](https://travis-ci.org/expressjs/serve-index.svg?branch=master)](https://travis-ci.org/expressjs/serve-index)
Usage:
```js
@@ -37,3 +39,6 @@ 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/).

View File

@@ -41,7 +41,7 @@ var defaultTemplate = join(__dirname, 'public', 'directory.html');
* Stylesheet.
*/
var stylesheet = join(__dirname, 'public', 'style.css');
var defaultStylesheet = join(__dirname, 'public', 'style.css');
/**
* Media types and the map for content negotiation.
@@ -67,6 +67,7 @@ var mediaType = {
* 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.
@@ -92,7 +93,8 @@ exports = module.exports = function directory(root, options){
, view = options.view || 'tiles'
, filter = options.filter
, root = normalize(root + sep)
, template = options.template || defaultTemplate;
, template = options.template || defaultTemplate
, stylesheet = options.stylesheet || defaultStylesheet;
return function directory(req, res, next) {
if ('GET' != req.method && 'HEAD' != req.method) return next();
@@ -130,7 +132,7 @@ exports = module.exports = function directory(root, options){
// not acceptable
if (!type) return next(createError(406));
exports[mediaType[type]](req, res, files, next, originalDir, showUp, icons, path, view, template);
exports[mediaType[type]](req, res, files, next, originalDir, showUp, icons, path, view, template, stylesheet);
});
});
};
@@ -140,7 +142,7 @@ exports = module.exports = function directory(root, options){
* Respond with text/html.
*/
exports.html = function(req, res, files, next, dir, showUp, icons, path, view, template){
exports.html = function(req, res, files, next, dir, showUp, icons, path, view, template, stylesheet){
fs.readFile(template, 'utf8', function(err, str){
if (err) return next(err);
fs.readFile(stylesheet, 'utf8', function(err, style){

View File

@@ -1,7 +1,7 @@
{
"name": "serve-index",
"description": "Serve directory listings",
"version": "1.0.0",
"version": "1.0.2",
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
"license": "MIT",
"repository": {
@@ -13,12 +13,12 @@
},
"dependencies": {
"batch": "0.5.0",
"negotiator": "0.3.0"
"negotiator": "0.4.3"
},
"devDependencies": {
"connect": "^2.13.0",
"mocha": "^1.17.0",
"should": "^3.0.0",
"connect": "~2.14.1",
"mocha": "~1.17.1",
"should": "~3.1.3",
"supertest": "~0.9.0"
},
"engines": {

3
test/shared/styles.css Normal file
View File

@@ -0,0 +1,3 @@
body {
color: #00ff00;
}

View File

@@ -161,6 +161,26 @@ describe('directory()', function(){
});
});
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);
});
it('should respond with appropriate embedded styles', function (done) {
request(server)
.get('/')
.set('Accept', 'text/html')
.expect(200)
.expect('Content-Type', /html/)
.expect(/color: #00ff00;/)
.end(done);
});
});
describe('when set with trailing slash', function () {
var server;
before(function () {