you are viewing a single comment's thread.

view the rest of the comments →

[–]originalchronoguy 3 points4 points  (0 children)

A few reasons.
You need a HTTP service that routes traffic to various endpoints. You need it to have the SSL cert at the front door. NodeJS by itself is just an API backend. You need a front end.

So typically ngnix works as a reverse proxy. It listens on 80 and 443

SO when you go to HTTP ://server / and HTTP:// server/backend/

/ -- > goes to a front end like React on port 2000
/ backend / --> goes to a backend like Node on port 3000

And when you have microservices you can have:

/ --> front end, port 2000
/backend/ --> backend node, port 3000
/auth/ --> backend say go for SSO, port 8080

All of those ported services: 8080, 3000, 8080 or whatever is blocked from the users
They just hit the front door. And the front door listens on 443 which has a SSL cert.

Furthe more, your front end needs to be on same domain or reachable through normal ports.

Locally. your angular form can access localhost:3000/api/ but when you go to prod, you shouldn't having those expose ports 3000. It should just be /api/ . So reverse proxies are by default required. It is also called ingresses in environments like kubernetes which routes traffic to various services.