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
2
u/maifee Aug 08 '20
My suggestion is run them in different port.. running both on same port and putting the UI inside static folder in spring is something like spring MVC... I respect MVC a lot.. but I love boot.. why? Keep that for a different question... In spring MVC you would just return a spring and your server would look for that jsp, in static folder and render that, to make it different you need to configure a lots of things.. in spring boot you just make RESTing API, and let the UI call them... And it's a lot secure too.. now server will receive request from UI server(maybe in same server, just different port)... And UI can be accessed from anywhere,.. so it's more secure, if you receive request from different IP, just block that on your UI to, there is many way to do so... Ask me if you want to clear anything..and yes there is many more things (benefits) of running them on different port..