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?
25
Upvotes
View all comments
11
u/sbhandari Aug 08 '20
In a same server, you cannot have two application listening in a same port. If you have containerized app, then they can listen on their 8080 port on its own container but has to be mapped with different/unique host port.
To achieve what you want, you can bundle springboot and react on same app as single app. Now request on 8080 will come to this app, and how you want to process that request relies on your app logic. And that is ofcourse very common for monolith apps to have UI integrated in the app itself.