0

I am currently working on a mean application, with an Angular frontend and an express/node backend. Frontend and backend communicate together with a REST API.

When I deploy the application, both the Angular front-end and the API back-end are served from the same port.

What consequences do running both on the same ports have, instead of separate port for each part?

1

The only consequence that I'm aware of for the markup and API being hosted from the same port on the same server is that they will be considered the same domain in terms of how browsers treat the request. This is actually a good thing in terms of security. It means that you do not have to be concerned with configuring CORS, and dealing with any potential misconfigurations.

2
  • "This is actually a good thing in terms of security It means that you do not have to be concerned with configuring CORS, and dealing with any potential misconfigurations". I can't agree with that. It is faster and simpler in terms of configurations. But not having to bother with CORS settings doesn't mean your solution is more secure.
    – Walfrat
    Nov 18 '20 at 12:01
  • 1
    My only response to that is that not needing to play with CORS configuration means less of a chance for misconfiguration. Nov 23 '20 at 17:15
0

Let's say you have 2 Servers running different APIs and want them to communicate with each other. If client and server are on the same port, they will not be able to communicate since the port is already on listen mode.

2
  • both front and back are running on the same server. backend API just have a prefix so there are no path used by both front and back. (www.example.com/users will call www.example.com/api/v1/users)
    – Kepotx
    Feb 26 '19 at 16:41
  • 2
    @Kepotx Maybe you should update your question to make it more clear. I take it you have a webserver listening on some port that serves 2 separate APIs, one for backend and one for frontend, and you're wondering about doing it this way vs listening on a separate port for each API? Your talk about "client" and "server" on the same port is confusing, what is the client and what is the server? Feb 26 '19 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.