I'm encountering an issue with fetching a JSON file in a Node-RED project. Here's the scenario:
Context:
I have a Node-RED setup where I serve a table.json file from the public folder.
The JSON file is accessed through a Vue.js component using the fetch method.
Issue:
When I initially start the Node-RED server, the JSON file is successfully fetched and everything works as expected.
However, after stopping and restarting the Node-RED server, I get a 404 (Not Found) error when attempting to fetch table.json.
Error Message:
The error in the console is: GET http://localhost:1880/table.json 404 (Not Found)
Current Setup:
The table.json file is located in the public directory of the Node-RED installation.
My fetch method looks like this:
async fetchData() {
try {
const response = await fetch('/table.json');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
this.desserts = data.desserts;
} catch (error) {
console.error('Error fetching data:', error);
}
}
Steps Taken:
- Verified that the table.json file is in the correct directory.
- Checked that the file path in the fetch request is accurate.
- Ensured the server is configured to serve static files correctly.
Additional Information:
- After restarting the server, accessing
http://localhost:1880/table.json
in the browser returns a 404 error.
Admin edit: Adjusted formatting for reabability.