You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/app # yarn list --pattern unenv
yarn list v1.22.17
└─ unenv@0.4.3
Reproduction
Reproduce the bug
After init the repo described in https://v3.nuxtjs.org/getting-started/installation
Add this api script to server/api/image.ts
exportdefaultasync(req,res,next)=>{constname=req.url.slice(1)// const value = await KV.get(name, {type: "arrayBuffer"}); // Uncomment when deploy on Cloudflareconstvalue=newUint8Array([255,216,255,224]).buffer;// The first four characters of jpegres.setHeader('Content-Type','image/jpeg');res.end(Buffer.from(newUint8Array(value)));// Return a binary data}
To temporary fix it, I remove .toString() in unenv and rebuild it for my project, it works, so I'm sure this is why the bug happened.
But I'm not sure the intention of adding .toString() for response in nuxt or unenv, thus I report this issue here, or shall we handle text and json ONLY on server/api?
Environment
Reproduction
Reproduce the bug
After init the repo described in
https://v3.nuxtjs.org/getting-started/installation
Add this api script to
server/api/image.ts
Result
$ NITRO_PRESET=cloudflare yarn build $ npx miniflare .output/server/index.mjs --site .output/public $ curl localhost:8787/api/image -s | xxd 00000000: efbf bdef bfbd efbf bdef bfbd ............
Both miniflare and Cloudflare given same result
Expected result
Describe the bug
The result
efbf bdef
in miniflare indicate the binary has been decoded, probably.toString()
method is triggered in somewhere.After tracing the code, I found that nitro use
unenv
to handle the response body of h3 server for Cloudflare deployment, wherethe response body has been decoded by
.toString()
in https://github.com/unjs/unenv/blob/main/src/runtime/fetch/call.tsTo temporary fix it, I remove
.toString()
in unenv and rebuild it for my project, it works, so I'm sure this is why the bug happened.But I'm not sure the intention of adding
.toString()
for response in nuxt or unenv, thus I report this issue here, or shall we handle text and json ONLY onserver/api
?Additional context
The code that related to this bugs:
Logs
No response
The text was updated successfully, but these errors were encountered: