Reputation: 560
I'm trying to get a Flask app to run on an EC2 instance. I have a few JS functions that send requests to the localhost
in the backend to retrieve data from an API.
For instance:
if(topicQueryString != null && topicQueryString != ''){
$.ajax({
url: 'http://0.0.0.0:5000/search/t/'+topicQueryString,
type: 'GET',
dataType: 'json',
success: function(data) { //do something }
})
}
However, when deploying the app on my EC2 instance, these requests fail with ERR_CONNECTION_REFUSED
on localhost:5000/search/t/topics
Is there a way to allow the EC2 instance to make requests to itself in this way?
Upvotes: 1
Views: 1075
Reputation: 37832
You're trying to connect to 0.0.0.0
, not localhost
. The address 0.0.0.0
doesn't mean localhost
. You should replace that with localhost
or 127.0.0.1
(which is what localhost means, most of the time).
EDIT: actually, I'm not even sure that I understood the problem correctly. Is that JS code running in a browser? You want that code to connect to a back-end service, presumably not running on localhost? If so, you should use the address of the back-end service, rather than 0.0.0.0
(which doesn't make sense in any context as a destination address to connect to) or localhost
.
Upvotes: 2