unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.89k stars 496 forks source link

useStorage().getItem() - different behaviour locally and on vercel #2481

Open nstdspace opened 4 months ago

nstdspace commented 4 months ago

Environment

Node: 20.14.0 Nitro(pack): 2.9.6

Reproduction

Reproduction repository, at commit getKeys() - 7d602f06b3ae2b87cbfdefff5ac58614fa6579f1

Describe the bug

In the case described above, locally I get a response with the content of x with the response header content-type: text/html. Deployed on Vercel, however, I get an empty response (204). In fact, returning getKeys() instead returns ['x'] locally but an empty array ([]) deployed on vercel.

This seems like a bug to me, so I preferred this example. The original problem I observed was something I cannot reproduce with nitro only: I have a file called x.b64 in a nuxt project. Locally, getItem returns just the content of the file in a string. On vercel I get an object looking like { "0": x, "1": y ...} with as many entries as there are bytes in the file and result[I] = byte at index i.

It seems to me that either vercel or nitro does something weird depending on the file ending, but I don't see exactly what.

Reading a pdf file produces a response with content type text/html but application/pdf on vercel (although the same content).

Where are those inconsistencies coming from?

Additional context

No response

Logs

No response

Barbapapazes commented 3 months ago

Hey, could you explain why are you trying to server something from an assets folder?

nstdspace commented 3 months ago

I have server assets like pdf templates which I load and modify on the server side on user request. According to examples I found online this is a common approach.

By the way, the fix I found is to use useStorage("assets:server").getItemRaw<string> which is sadly marked as experimental - but it does what I need.