Skip to content

Commit

Permalink
fix: enable format only index exists
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxin committed Oct 21, 2015
1 parent 5184d0d commit e7ffbdf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function send(ctx, path, opts) {
// and not require a trailing slash for directories,
// so that you can do both `/directory` and `/directory/`
if (stats.isDirectory()) {
if (format) {
if (format && index) {
path += '/' + index;
} else {
return;
Expand Down
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,19 @@ describe('send(ctx, file)', function(){
.get('/')
.expect(200, done);
})

it('should 404 if no index', function(done){
var app = koa();

app.use(function *(){
var opts = { root: 'test' };
yield send(this, 'fixtures/world', opts);
});

request(app.listen())
.get('/')
.expect(404, done);
})
})

describe('when path is malformed', function(){
Expand Down

0 comments on commit e7ffbdf

Please sign in to comment.