My data.json is in the top level of my nuxtjs folder. But yet still, this json file cannot be accessed with this fetch. The URL is not publicly accessible. My server is listening to private IP address of 172. So I presumed the public URL for it would be my replit domain but I keep getting a 404 error when it tries to retrieve that data.json.
Interesting. The only file I see to specify the IP in, is set properly. I guess verify that the URL you’re requesting the data from is correct. Otherwise I have no clue, I haven’t worked with Nuxt.js before.
Always use ./ instead of your website URL when using local files as this ensures that the file can be accessed even when the URL of the website is changed.
I should have clarified to say “in my case” - which is me running the fetch on server-side. And naturally servers don’t have concept of relative URLs…only the browser. So I’m going to work on adding an environment variable instead.
The code is NodeJS running on the server, not JavaScript running in the browser. The server doesn’t know where it is hosted, it could be hosted in multiple places, so server-side fetch can’t support relative urls.
As @9pfs1 said, if the JSON file is on the server and this code is in the server, use the node:fs module built-in to NodeJS. That way you can read the file data without sending an actual request. Sending a request will only work if the JSON file is hosted, which I suspect it isn’t.