How to male front-end angularjs code communicate to backend java code on same ec2

I have an EC2 instance on a private subnet.

I have a Java Spring-boot application deployed using nohup on it on port 8080

I have another front-end application in AngularJS which is run using grunt and pm2 on the same EC2 on port 9000.

The front end application communicates with the java backend on localhost.

In the front-end code, I use the $http library to call the java APIs like this:

  method: 'GET',
  url: 'http://localhost:8080/myserv/getdata',
  headers: {
    'Content-Type': '*/*'
}).then(function (response) {
  // processing data...
function (err) {
 console.log('ERROR: ' + JSON.stringify(err));

The EC2 instance itself is on a private network and It is exposed through an ELB which redirects all internet traffic to localhost port 9000 on EC2.

Now, when I open the application through my browser, I can see the UI correctly, but in the dev console, i gives error:

Failed to load resource: net::ERR_CONNECTION_REFUSED

So, I think it is not able to communicate with the backend API.

On the EC2, when I do a curl on http://localhost:9000/home/ and on http://localhost:8080/myserv/getdata, both give correct response, so both the applications are running file, then why isn’t the front-end able to communicate with the back end?

How do I fix this ?

Source: AngularJS