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.

1 thought on “Configuring JS frontend depending on how the app was deployed”

  1. You can have the backend deployed in a subdomain

    deploying in different place is the best solution

    Since you are using react you can deploy it without the need for a node js server you can build and deploy it in a cdn and route all the request to the index.html unless you need SSR you dont need a Nodejs deployment you can deploy it in Firebase or netlify for instance as an SPA and have the java backend in a vps of your choice Suggestion:Heroku or digital ocean



Leave a Comment