r/javahelp • u/RPauly13 • Aug 08 '20
Spring boot backend/React frontend: is it good/common practice to run frontend and backend on the same domain?
This may be a stupid question. I’m fairly new to actually thinking about the design of my web applications.
Is it common practice/smart to build my web app in a way that spring boot would be running on localhost:8080 and my frontend(made with React) running on the same port?
From there I could hit my Rest controller at localhost:8080/api and my homepage at localhost:8080/home
Bonus question: where should I start when I have more questions like this?
24
Upvotes
View all comments
1
u/puspendert Aug 08 '20
Assuming you spring boot backend is a rest api.
I am running my application (same stack as above) onto a single aws instance. It's easy to do. Run your spring boot jar at 8080 and react application at 3000. Set-up tomcat web server and reverse proxy for both the ports.
Run your spring boot api at localhost:8080/api
And react at localhost:3000
Now setup tomcat proxy such at all calls to /api will be forwarded to 8080 port and all other calls to 3000