From d87d8e5f7a426409565d1a008b8231c793ec61ef Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 19 Nov 2020 18:44:56 +0100 Subject: [PATCH] fix: stop middleware when writableEnded flag is set --- src/app.ts | 4 ++++ test/fixture/server.js | 1 + 2 files changed, 5 insertions(+) diff --git a/src/app.ts b/src/app.ts index 9fa6ee57..d1614302 100644 --- a/src/app.ts +++ b/src/app.ts @@ -21,6 +21,10 @@ export function createApp (): App { const val = await layer.handle(req, res) + if (res.writableEnded) { + break + } + const type = typeof val if (type === 'string') { send(res, val, MIMES.html) diff --git a/test/fixture/server.js b/test/fixture/server.js index 22ef5ffd..f788238d 100644 --- a/test/fixture/server.js +++ b/test/fixture/server.js @@ -14,6 +14,7 @@ const app = createApp() app.use('/api/hello', req => ({ url: req.url })) app.use('/api/express', createExpress()) +app.use('/api', (_req, res) => { res.end('API root') }) app.use('/', () => 'Hello world!') const port = process.env.PORT || 3000