Skip to content

Commit

Permalink
fix index: false bug if path is directory
Browse files Browse the repository at this point in the history
fix `index: false` bug if path is directory

Revert "fix `index: false` bug if path is directory"

This reverts commit b952196.

fix `index: false` bug if path is directory

closes #104
  • Loading branch information
Cap32 authored and haoxin committed Jul 9, 2017
1 parent d2b6dbb commit 1328f78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 6 additions & 4 deletions index.js
Expand Up @@ -37,16 +37,18 @@ function serve (root, opts) {

if (!opts.defer) {
return async function serve (ctx, next) {
let done = false

if (ctx.method === 'HEAD' || ctx.method === 'GET') {
try {
await send(ctx, ctx.path, opts)
done = await send(ctx, ctx.path, opts)
} catch (err) {
await next()
}
return
}

await next()
if (!done) {
await next()
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/index.js
Expand Up @@ -132,6 +132,19 @@ describe('serve(root)', function () {
.get('/world/')
.expect(404, done)
})

it('should pass to downstream if 404', function (done) {
const app = new Koa()

app.use(serve('test/fixtures', { index: false }))
app.use(async (ctx) => {
ctx.body = 'oh no'
})

request(app.listen())
.get('/world/')
.expect('oh no', done)
})
})
})

Expand Down

0 comments on commit 1328f78

Please sign in to comment.