0

I'm looking for a solution to my development flow problem.

In a nutshell, I have a front-end (React, NPM) and a back-end (Spring Boot 2, Gradle)

I'd like to have the back-end serve the front-end files itself (instead of serving them via a separate Express server which I've done in the past).

However, I don't want to put them in the resource directory and have the back-end build pipeline to also build the front-end, because they I'd have to recompile for each little change. Instead, I'd like to be able to use an NPM command (like npm start) which will watch and build my front-end code continuously.

This means I want the front-end files to be outside of the otherwise standalone JAR.

My problem is, I can't figure out a good mechanism to be able to reference it in a relative manner. I know I can put it at an absolute path to find it, but that would mean each dev has to set that up (and doesn't work if multiple projects are being developed with the same type of workflow).

How can I either reference my public directory in a relative way or otherwise have those files built outside the back-end build pipeline?

samanime
  • 25,408
  • 15
  • 90
  • 139
  • You can specify an additional resource handler to make spring to also look for resources in an external location. See https://stackoverflow.com/questions/28556300/serving-static-resources-from-file-system-spring-boot-web – Alberto Hormazabal Aug 09 '18 at 15:40
  • If I do that, I'm pretty sure it'll pull it into the resources when it builds, which means it'll only pick up the changes whenever I recompile the back-end, which I want to avoid. – samanime Aug 09 '18 at 15:48
  • 1
    Why would it not pull in the updated resources after they change? Assuming of course you set the cache period appropriately – Ben M Aug 09 '18 at 16:02
  • I want the static files to be build continuously with an NPM task, running separate from the Gradle one which builds the back-end. I want to be able to have the back-end running, update the front-end, then see the changes (without having to restart the back-end). – samanime Aug 09 '18 at 17:00
  • Adding a resource handler to your application (not build spec), pointing to an external path, will make spring look for resources on that external path AT RUNTIME. At most you should have cache issues as Ben noted, which is easy to configure. Did you at least bothered to read the referenced question and accepted answer? – Alberto Hormazabal Aug 10 '18 at 16:28

0 Answers0