BookLore icon indicating copy to clipboard operation
BookLore copied to clipboard

Serve Angular app directly from the Java backend

Open wariuccio opened this issue 2 months ago • 4 comments

Hello, I was looking at the Dockerfile and at the configuration and I noticed that Nginx there is adding some complexity. Admittedly not too much but not zero.

I am wondering if Nginx is actually required or if the Angular app could be served directly by the Java backend. This would remove Nginx running from inside the Docker container (which is a win). Usually I like to have a single process in each container for ease of maintenance.

Personally when I use Docker containers I already have a reverse proxy in front of all of them that does a simple proxyPass to whatever the container is doing. I can still do it with BookLore but that means that I have now 2 reverse proxies running, my own and the ones inside the Docker container.

If possible, I think this chance would be a win by reducing both the configuration and operational complexity of running BookLore. This would also help addressing the root cause of https://github.com/booklore-app/booklore/issues/1344 and https://github.com/booklore-app/booklore/issues/1374

wariuccio avatar Oct 21 '25 16:10 wariuccio

I’m interested in implementing this change. Would you be willing to collaborate on it?

acx10 avatar Nov 27 '25 01:11 acx10

I can try to have a look but I'm not familiar with Angular nor with Spring Boot. Good reason to learn something new :)

Should I create a PR once I am ready (it might take a while) or were you thinking to collaborate in some different way?

wariuccio avatar Nov 28 '25 15:11 wariuccio

@wariuccio A PR would be great, that way we can review and iterate on it once you’re ready.

acx10 avatar Nov 28 '25 21:11 acx10

Sounds good. So far I only had time to have a cursory look and this is what I discovered.

Dev

The dev workflow should be left as it is. It currently doesn't involve Nginx and there is value in running the UI and the API independently so we can have nice things such as ./gradlew bootRun and ng serve watching the files for changes and rebuilding reloading as appropriate.

Prod

For the production workflow there are a couple paths we can take. I think keep building the UI as we do now, and reference it from the Spring boot app is the best path forward.

The Dockerfile is already building the Angular app and then copying it inside the Nginx container.

We could keep it as it is and remove the Nginx from the Dockerfile, remove start.sh and instead execute directly java -jar /app/app.jar.

For this to work we need to adjust a couple things in the API backend:

  • we need to make it serve the files we have on disk. According to this it should be a simple edit to WebMvcConfig
  • make sure that the backend routes correctly /api/**/ to the API, /ws/** to WebSockets and looks for the Angular UI on the filesystem. I need to check how to do that but it doesn't sound hard
  • re-create the logic in Nginx configuration to fall-back to Angular routing.

For sake of completeness, there is also the option to have Gradle build the Angular app and to embed it in the archive it generates. I wouldn't go that route though to minimise the difference with what we have now and to avoid getting ourself in the situation where to debug issues in the build of the Angular app in production we need to both understand how Angular works and how it integrates with Gradle.

wariuccio avatar Nov 28 '25 22:11 wariuccio

@adityachandelgit what we have in #1679 should be working

wariuccio avatar Dec 05 '25 14:12 wariuccio