N
Nuxt2y ago
cosbgn

How to use static `files` with server functions?

I have a /server/api/foo.js functions which does something like this:
export default defineEventHandler(async (event) => {
const db = JSON.parse(readFileSync(new URL(`../../server/files/colors.json`, import.meta.url), 'utf8'))
export default defineEventHandler(async (event) => {
const db = JSON.parse(readFileSync(new URL(`../../server/files/colors.json`, import.meta.url), 'utf8'))
This works with nuxt dev but when I deploy to vercel it can't find the file. Where should I put it? Is there something like ~assets for back-end functions? P.s. the file is readonly, I know vercel can't write anything since it's serverless. But I would still be able to read it.
1 Reply
cosbgn
cosbgnOP2y ago
For whoever finds this the solution is to use UseStorage() like this https://github.com/unjs/nitro/issues/914#issuecomment-1479756447
GitHub
Server Assets default path confuse · Issue #914 · unjs/nitro
Environment nitropack v2.1.1 node v16.14.2 Reproduction Files assets/data.json "File: assets/data.json" assets/server/data.json "File: assets/server/data.json" server/assets/dat...
Want results from more Discord servers?
Add your server