committed by
Douglas Christopher Wilson
parent
5771318d78
commit
e40300aa86
9
index.js
9
index.js
@@ -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.
|
||||
@@ -93,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();
|
||||
@@ -131,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);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -141,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){
|
||||
|
||||
3
test/shared/styles.css
Normal file
3
test/shared/styles.css
Normal file
@@ -0,0 +1,3 @@
|
||||
body {
|
||||
color: #00ff00;
|
||||
}
|
||||
20
test/test.js
20
test/test.js
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user