Skip to content

Commit d87d8e5

Browse files
committed
fix: stop middleware when writableEnded flag is set
1 parent 2fb92ef commit d87d8e5

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

src/app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export function createApp (): App {
2121

2222
const val = await layer.handle(req, res)
2323

24+
if (res.writableEnded) {
25+
break
26+
}
27+
2428
const type = typeof val
2529
if (type === 'string') {
2630
send(res, val, MIMES.html)

test/fixture/server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const app = createApp()
1414

1515
app.use('/api/hello', req => ({ url: req.url }))
1616
app.use('/api/express', createExpress())
17+
app.use('/api', (_req, res) => { res.end('API root') })
1718
app.use('/', () => 'Hello world!')
1819

1920
const port = process.env.PORT || 3000

0 commit comments

Comments
 (0)