Configuring JS frontend depending on how the app was deployed

I have a Java+React web application. There are two options of how to deploy it:

  1. You launch backend with Spring Boot and React with Node.js separately.
  2. You build a .ear with bundle.js building with frontend-maven-plugin and then deploy it on an app server.

The thing is that in the first case Spring Boot launches, for example, on localhost:8080 and Node.js on localhost:8081, they need different ports. And in the second case everything is in the same place and with completely different address. For the second case, when I make requests from frontend to backend I can just skip domain name and write a path. But in the first case I have to specify domain name since backend has different domain name.

My question is how to solve this problem and make frontend understand how the app was deployed. I can think of something like passing an argument with node.js command or something, but not sure if that is a correct and neat way of doing that.

I can provide the code if needed.

14 thoughts on “Configuring JS frontend depending on how the app was deployed”

Leave a Comment