Read files in API route, fails on Vercel
I have a simple API request that reads some dirs and files and creates a response out of it.
In the Vercel's docs, I read that I have to use
process.cwd()
but that does not help.
Previously, I had presets
inside of a server
directory, but that did not work on Vercel, so I moved it to the public. Obviously, hoped it would work, but it's the same. It cannot find the directory.
I also read somewhere that Nuxt supports useStorage()
to have server assets, but I do not think that's what I need here, or is it?3 Replies
process.cwd()
returns:
So no wonder it cannot read from public dir. How to make it read from public directory tho?
Seems like it's unresolvable. Spent all day trying to figure it out with different approaches and nothing worked.
Had to rewrite all the logic and use Vercel's Postgres + Drizzle.is it normal ssr or vercel edge? In my case whenever I need to read files in Nuxt/Nitro I use
useStorage
as it provides better typed and also to not enter the loophole to where are my files 😂.
this is nito's docs on useStorage
https://nitro.unjs.io/guide/assetsYea, I tried that before the rewrite too. But it was not convenient for me, because one of my endpoints indeed needed to go through all as directories were parameters and filenames were ids.
If you know what I mean... And with this hook, it's not not possible to list all, without knowing the path and filename.