I am running preact in a Node Docker, and a rest-api in a phpapache docker.
- docker run --network vumc-network -p 80:80 --name phpapache phpapache
- docker run -p 4200:4200 --network vumc-network --name node node
When i log in the node docker I can execute:
const http = require('http');
http.get('http://phpapache/nl/menu', (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log(data);
});
}).on('error', (error) => {
console.error(error);
});
which correctly returns a json.
But in de react-app is a function that does something similar:
fetch('http://phpapache/nl/menu')
.then(res => res.json())
.catch(error => {
console.error(
"There was a problem loading the database from DatabasesNav",
error
);
});
which fails with an error: TypeError: Failed to fetch