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?


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.

  • 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
  • 1
    @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? – AndrolGenhald Feb 26 '19 at 16:45

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.

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.