diff --git a/index.js b/index.js index 46ae4a9..e8110d7 100644 --- a/index.js +++ b/index.js @@ -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() + } } } diff --git a/test/index.js b/test/index.js index b3c1347..e2ea964 100644 --- a/test/index.js +++ b/test/index.js @@ -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) + }) }) })