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
3
u/deathmetal27 Extreme Brewer Aug 08 '20
If you really want to do this, you could serve your react app in your web application. This way, your frontend and backend, both run on the same port. I have seen some applications do this and the advantage here is that you don't have to deal with CORS issues.
Though I have also seen lots of projects where the front end and back end run as separate applications. In such cases, its best to use a reverse proxy to ensure that both your front end and back end are on the same domain to avoid CORS related issues.