suharsha
suharsha

Reputation: 115

ReactJS proxy URL for localhost API in PROD when bundling with Spring Boot

I'm trying to bundle ReactJS and Spring Boot API together and build one fat jar. In every tutorial I read, I'm told to put the localhost API URL as a proxy in package.json of the React app like below.

"proxy": "http://localhost:8080"

As I obviously don't have PROD deployment experience with this, is this the way to go when you are deploying in PROD? Else, please guide me in the right direction. I couldn't find the answer anywhere.

Also, any cons in doing so in a medium sized project with two developers? Appreciate any input.

Upvotes: 1

Views: 1702

Answers (1)

Roie Beck
Roie Beck

Reputation: 1175

The "proxy" field should only be used in development environment when the Webpack dev server is first in line(to enable the Hot-Reload feature) Here is a guide from 2018: spring + react guide

regardless there are two main way of hosting the react app:

  1. inside the spring boot Jar a static resource(you can use frontend-maven-plugin to run yarn/ npm again see the guide), the advantages of this method is security, you don't need CORS enabled to serve the page. the disadvantages is convenient this solution require more code, also the spring boot server handles UI serving to the client that requires extra calls to the server(spring first approach)
  2. the other option is to host it in a hosting service like amazon S3 and then it will be hosted not in spring but in s3 and will be the first in line(UI first approach), you will need to enable CORS in spring boot app, but this is a more continent solution.

ps. I would read some guides first, it would help you with general understanding

Upvotes: 1

Related Questions