I am trying to link make an API call to my back end to test that my server is running. I am using React on the front and and Node.js with express on the back end.
My back end endpoint is very simple:
app.get('/', (req, res) => {
console.log('hit')
const name = req.query.name || 'World';
res.setHeader('Content-Type', 'application/json');
res.send({
greeting: `Hello ${name}!`,
});
});
and on the front end I am making the request:
React.useEffect(() => {
fetch('http://localhost:3001//')
.then((res) => res.json())
.then((data) => {
console.log(data);
})
.catch(console.log('error'));
});
I added console logs to try and track down the mistake. I get 'error' logged to the console. Additionally I get console errors that read:
Access to fetch at 'http://localhost:3001/' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
manifest.json:1 GET http://localhost:3000/manifest.json 404 (Not Found)
manifest.json:1 Manifest: Line: 1, column: 1, Syntax error.
I haven't seen this manifest.json warning before.