Skip to content

Commit

Permalink
fix judgement of trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxin committed Oct 14, 2015
1 parent 6c75e42 commit ed01c33
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ function send(ctx, path, opts) {
// options
debug('send "%s" %j', path, opts);
var root = opts.root ? normalize(resolve(opts.root)) : '';
var trailingSlash = '/' == path[path.length - 1];
path = path[0] == '/' ? path.slice(1) : path;
var index = opts.index;
var maxage = opts.maxage || opts.maxAge || 0;
var hidden = opts.hidden || false;
var gzip = opts.gzip || opts.gzip === undefined ? true : false;

return function *(){
var trailingSlash = '/' == path[path.length - 1];
var encoding = this.acceptsEncodings('gzip', 'deflate', 'identity');

// normalize path
Expand Down
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ describe('send(ctx, file)', function(){
.expect(200)
.expect('html index', done);
})

it('should serve it', function(done){
var app = koa();

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

request(app.listen())
.get('/')
.expect(200)
.expect('html index', done);
})
})
})

Expand Down

0 comments on commit ed01c33

Please sign in to comment.