0
votes

I have 2 applications. Client is developed on react js and server is developed on spring boot using RESTful api. Both are working fine on localhost. I tried to deploy both apps on heroku. Server is working fine with postgres db on heroku (checked on postman). However, when I deployed react app on heroku as seperate app, its only showing me UI without data (from spring boot webservice). I changed the web service URL (used locally as http://localhost:8080) in react app to heroku server app URL(provided by heroku). Now its working. But, I don't know whether its correct way to configure.

Do anybody know, how to deploy server (Spring boot) and client (React js) both on heroku in right way?

1
Can you be more Specific Which kind of error are you getting. Check the console of the browser or give error from the network Tab. It will be more useful to debug things like this. - Parth Patel
I have edited question. I want to know if there is any appropriate way provided by heroku. - Abhishek

1 Answers

1
votes
  • I can say that use a .env file is a good way to provide the environment variable. Generally in production, these values come from the environment. So in code, we will have the placeholder/variable only so that we can use that thing to change the URLs and other public thigs like that with env file. And One more thing is that you can also override the default value in env file with an external Heroku dashboard env's.

WARNING: Do not store any secrets (such as private API keys) in your React app!

Environment variables are embedded into the build, meaning anyone can view them by inspecting your app's files.

Please refer to the documentation for usage :

So For REACT_APP_NOT_SECRET_CODE this env variable we can use code like this:

*`<input type="hidden" defaultValue={process.env.REACT_APP_NOT_SECRET_CODE} />`*

I hope this will answer your question.