Skip to content

Commit

Permalink
fix issue with Lambda where streaming repsonses always require a body…
Browse files Browse the repository at this point in the history
… to be present
  • Loading branch information
adrai committed Jan 27, 2025
1 parent c8a7dff commit 5f1f1fa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ module.exports = (app, options) => {
headers: {}
})
}
const stream = res.stream()

This comment has been minimized.

Copy link
@spaceemotion

spaceemotion Jan 27, 2025

@adrai was the extra check to see if the response is available needed? the update removed that check, but I wasn't sure if that was intentional

This comment has been minimized.

Copy link
@adrai

adrai Jan 27, 2025

Author Member

Was not able to trigger an error there, but just to be sure I added it back to v5.1.4

return resolve({
meta: {
statusCode: 500,
headers: {}
},
stream: (res && res.stream()) || require('node:stream').Readable.from('')
// fix issue with Lambda where streaming repsonses always require a body to be present
stream: stream.readableLength > 0 ? stream : require('node:stream').Readable.from('')
})
}
// chunked transfer not currently supported by API Gateway
Expand Down Expand Up @@ -171,9 +173,11 @@ module.exports = (app, options) => {
return resolve(ret)
}

const stream = res.stream()
resolve({
meta: ret,
stream: res.stream()
// fix issue with Lambda where streaming repsonses always require a body to be present
stream: stream.readableLength > 0 ? stream : require('node:stream').Readable.from('')
})
})
})
Expand Down

0 comments on commit 5f1f1fa

Please sign in to comment.