Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nstdspace opened this issue May 30, 2024 · 2 comments
Open

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

nstdspace opened this issue May 30, 2024 · 2 comments

Comments

@nstdspace
Copy link

Environment

Node: 20.14.0
Nitro(pack): 2.9.6

Reproduction

  • Create a new nitro app via npx giget@latest nitro nitro-app --install
  • Create the directory server/assets
  • Add a file named "x" with any content
  • Inside of the index event handler, replace the default content with
const storage = useStorage("assets:server");
return storage.getItem("x");

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
Copy link
Member

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

@nstdspace
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants