I've got a React app build with Create-React-App running inside a docker container.
This code:
const req = new Request(
apiAdminUrl + '/login', {
method: 'POST',
body: formData
}
return fetch(req).then(processResp, processErr);
Returns TypeError: Load failed
, "Failed to load resource: A server with the specified hostname could not be found."
But the curl request from the same container works without issues:
curl -d "email=admin@some.etc" -d "pwd=xxx" -X POST http://api-admin:3000/v1/login
CORS is enabled in the api code. apiAdminUrl
is properly set as http://api-admin:3000/v1
.
What am I missing?
Top comments (2)
You can also add a
hostname
to your container, such as api.localhost. Or use a reverse proxy container, such as nginx or traefic.Ok, solved. As pointed to me elsewhere, obviously local browser environment doesn't see the network structure of the container. I need to use the local api address.