Skip to content

Commit

Permalink
fix: handle no data no fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 15, 2024
1 parent 8cf7365 commit 3ddeb1a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/send/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ const pickHeaders = headers =>
module.exports = ({ type, data, req, res }) => {
const { query } = req
const statusCode = data ? 200 : 404
return query.json
? send(res, statusCode, { url: data })
: type === 'buffer'
? send(res, statusCode, dataUriToBuffer(data))
: got.stream(data, { headers: pickHeaders(req.headers) }).pipe(res)

if (query.json) {
return send(res, statusCode, { url: data })
}

if (type === 'buffer' || data === undefined) {
const responseData = data === undefined ? data : dataUriToBuffer(data)
return send(res, statusCode, responseData)
}

const stream = got.stream(data, { headers: pickHeaders(req.headers) })
return stream.pipe(res)
}

0 comments on commit 3ddeb1a

Please sign in to comment.