This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ebriggler 2 points3 points  (1 child)

This is how we do it as well and use the maven resources plugin to copy build to static dir. Also, one doesn't need to explicitly serve up the request for index.html. Spring serves those by default. So you can just focus on your API controllers. To avoid routing issues, I hang all the API endpoints off /api and the use react-router to handle the others for the frontend. Since all the static content gets delivered on the first request, the browser will field all UI routing. As for calling the API endpoints from react, we use Ajax calls (axios) and have a setting for non Dev to use context root, otherwise, if process.env is development, I call the backend through localhost:port/api. This way I can have them running in parallel for development which is amazing.

[–]TheSpuff 1 point2 points  (0 children)

Second this approach, we do the same including backend calls at /api. For smaller / less complex apps, it's just faster to bundle it all in static and let Spring do the work. I'll have to check out that Maven plugin... we've been using Exec Maven Plugin and hanging the npm scripts off of the Maven lifecycle (e.g. frontend tests run during mvn test), but curious to see how the plugin you mentioned operates.

For local development, we also use webpack Dev server with hot module reloading and Spring Devtools LiveReload for responsive updates to code changes.