'Angular/Node.js, what's the ports when deployed?
I am currently building an app with Angular and NodeJS. On a development environment, it's quite easy, Angular is on port 4200 and I fetch response from Node.js which is on port 3001, for example:
constructor(private http: HttpClient) {
this.http.get('http://localhost:3001/api/series').subscribe(data => {
this.data.push(data);
console.log(this.data);
}, error => console.error(error));
}
But how does it work when I will want to deploy it on a domain, let's say "https://example.com"?
Solution 1:[1]
If it's https, it's going to be port 443. If it's http, it will be port 80.
This is a convention, but it's almost always followed. If anyone doesn't believe me, just open inspect element and go to any website. Check the network log.
- Google: 142.250.217.68:443
- Stack overflow: 151.101.1.69:443
- literally example.com: 93.184.216.34:443
- Reddit: 151.101.1.140:443
Note: this is fundamentally different from the port that might actually get contacted on the physical box running the code. For example: you get google by going to 142.250.217.68:443. This address represents tons of machines, and your request will get routed to one of them. Each machine has it's own local ip address and port, which can be literally anything. So your code might be hosted on 192.168.1.254:1234 within a datacenters local network, but users will still use [some ip]:443 to get to your website.
Edit based on feedback from jonrsharpe: You absolutely do not need to specify these ports. You can just send requests to https://example.com/ and your server will get them. All the port nonsense pretty much gets taken care of by other people
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
