Skip to content

Commit

Permalink
fix: stop middleware when writableEnded flag is set
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 19, 2020
1 parent 2fb92ef commit d87d8e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/fixture/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d87d8e5

Please sign in to comment.