Search code examples
node.jsangularamazon-web-servicesweb-applicationsaws-application-load-balancer

How do I fix the Error when setup AWS Application Load Balancer For Angular+NodeJS Web Application


I set up an Application Load Balancer(AWS) for my website. In my website, I have angular as my frontend, and I have NodeJs and Neptune DB as my backend.

Browser(Local Machine) -> ALB -> EC2 Instance(Web).

I have an url for my web(https://example.com), so when I made a request to https://example.com in my local machine browser, Angular will do a api call using httpclient.get() to fetch data from nodejs at https://example.com/api/ticket.

So my question is when Angular fetch data from NodeJS, will the api call bypass the ALB, what is the host then? Or NodeJs will recognize the request is from the local?


Solution

  • I assume you are using an ALB with Host based routing. In this case you can have a 443 rule for example.com forwarding requests to the EC2 instance. Then in the Nodejs application you can have that api called using the same url.

    This means that the request will be routed through the ALB which is also the best practise to do the same.