A sample project to showcase how to implement Server-Sent Events (SSE) from a Spring Boot backend and an Angular frontend.
- Java 17+
- Maven 3.9+
- Node.js 18+ and npm
- Git Bash (Windows) or any shell with GNU Make available
- On Windows you can install Make via:
choco install make(Chocolatey) orwinget install GnuWin32.Make, or use Git Bash which already provides a POSIX shell.
- On Windows you can install Make via:
This repository includes a Makefile that builds and runs the backend first and then the frontend.
Common targets:
make build— builds the backend (Spring Boot) and the frontend (Angular) in sequence.make run— starts the backend first, waits for it to be up, then starts the Angular dev server.make start— alias formake run.make clean— cleans Maven artifacts and removesdist.
- Backend
- Location:
apps/backend/provider-service - Port:
8080(default Spring Boot)
- Location:
- Frontend (Angular via Nx)
- App name:
provider - Dev server port:
4200 - A dev proxy is configured so that
/ssecalls are forwarded tohttp://localhost:8080(seeapps/provider/proxy.conf.json).
- App name:
- Install dependencies for the frontend if you haven’t yet:
npm install
- Build both projects:
make build
- Run both (backend first, then frontend):
make run
- Backend will start on
http://localhost:8080/ - Frontend dev server will start on
http://localhost:4200/
- Backend will start on
Press Ctrl+C in the terminal to stop the frontend dev server. If the backend continues running, stop it from the same terminal session (it will often terminate when the shell exits) or kill the Java process manually.
If you prefer to run pieces manually or don’t have Make:
- Start backend (from repo root):
mvn -f apps/backend/provider-service/pom.xml spring-boot:run
- In a second terminal, start the frontend dev server:
npx nx serve provider
- If
makeis not found on Windows, use Git Bash or install Make via Chocolatey/Winget as noted above. Alternatively, use the manual commands in the section above. - If port 8080 is in use, change Spring Boot’s port (e.g.,
--server.port=8081) and updateapps/provider/proxy.conf.jsonaccordingly, or runmakewith a different port:BACKEND_PORT=8081 make run. - If port 4200 is in use, run the Angular dev server with a different port:
npx nx serve provider --port=4300.