Replies: 1 comment 2 replies
-
Note that the code above works on my local machine but does not work on the vercel deployment. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello All,
I'm trying to use useSWR to fetch json5 data using a
/pages/api/[...relativePath]
dynamic route, to fetch data from a FS location by specifying a relative path. I URI encode/decode the path across the wire.It is erroring out giving me a ENOENT File not found error on the server.
Note that I also have a
/pages/api/metadata.js
route that works with useSWR, and I can fetch a json5 file using a hardcoded path./data/static/provider/XYZ/*.json5
(does not work) and/data/static/metadata.json5
(works) is where my data is stored in my project.*****I use path.resolve to get the absolute path of "./" on the server based on this article. I did not use this solution to get the location of the files on the file system.
==================================================================
Error on the server: Functions:
=================== /pages/api/metadata.js =====================
================== Caller of /api/metadata.js ======================
const { data, error } = useSWR('/api/metadata', fetchJson5)
------> This works!
====================Log from server from /pages/api/metadata.js:=====================
What am I missing? I thought catch-all paths should be possible with SWR. It would be super elegant if this worked. I think my other option is to pass a query parameter with the relative path in
useSWR('/api/alldata?path=/data/static/../etc', fetchJson5)
instead of using dynamic routes.Here's the vercel example that uses the dynamic route
/pages/api/[id].js
, that I am trying to mimic, but additionally using a catch-all route of ``[...id].js``` with useSWR.Any advise would be greatly appreciated.
Thanks so much!
Beta Was this translation helpful? Give feedback.
All reactions