Just as background, I have a react app sitting on a remote EC2 Ubuntu instance. The same server also runs a Go app listening on port 8080 (port has been opened to everyone from the Security settings).
I am trying to make a request with Fetch API, from the React app, as follows:
var bearer = 'Bearer ...'
return fetch('http://localhost:8080/home', {
headers: new Headers({
'Authorization': bearer
})
})
In the console, from both Chrome and Firefox, I am getting:
TypeError: NetworkError when attempting to fetch resource
The same goes when I substitute localhost
with 127.0.0.1
.
Using the external IP of the EC2 instance, however, works (and triggers a CORS request - due to the 'Authorization' header - which is handled smoothly by the server).
In the latter case, I can also see the server logging the incoming request for both OPTIONS and GET (in the former case, no logs are present for either method).
I also tried CURL'ing from the EC2 machine to localhost
and the request effectively goes through which leads me to think that with the Fetch API the request is not triggered at all.
Any advice would be appreciated. If I am doing anything wrong please point me in the right direction.