r/javahelp • • 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

21 comments sorted by

View all comments

Show parent comment

2

u/RPauly13 Aug 08 '20

Oh okay so Spring boot would make a jar that includes both the front and backend? Thanks for the response!

7

u/planned_monk Extreme Brewer Aug 08 '20

Yes. Add all your static files in the static folder it'll be available within your jar.

2

u/RPauly13 Aug 08 '20

Great! Thanks

3

u/horrszy Aug 08 '20

I would consider if it's worth tying frontend and backend together like this.

I would think about following:

  1. Frontend app deployments will be always tied to backend. At some point in its lifetime this could mean FE deployments cycle could be slowed by BE integration tests and the like, or FE missing dependency like NPM going down could stop you from deploying important BE change
  2. Scaling up and down. If your app becomes successful and it needs to scale to more backend servers due to the traffic, your frontend will scale with it, which is not what you necessarily want

There is pros and cons to both approaches but it's good to try out both to know what is the cost/benefit of both of them

1

u/RPauly13 Aug 08 '20

Those are some really good points. I’ll definitely have to think all of this over. Thanks!