Skip to content

Repository files navigation

Spring Petclinic Angular

Build Status

Angular frontend for Spring Petclinic

Warning: client only. Use the REST API from the backend spring-petclinic-rest project. Start the backend server before using workflows that call the API. The frontend expects the Spring Petclinic REST API at http://localhost:9966/petclinic/api/.

Screenshot

Screenshot of SPring Petclinic Angular

Installation

Use Node.js 24.x and npm. The project uses Angular 22 and keeps the Angular CLI as a local dev dependency.

nvm use
npm ci

For a fresh dependency resolution during maintenance, run npm install and commit the regenerated package-lock.json.

Development server

Run npm start for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Code scaffolding

Run npm run ng -- generate component component-name to generate a new component. You can also use npm run ng -- generate directive|pipe|service|class|module.

Build

Run npm run build to build the project. The build artifacts will be stored in the dist/ directory. Use npm run build -- --configuration production for a production build.

You can also build the application in a dedicated docker image using the provided Dockerfile as follows:

docker build -t spring-petclinic-angular:latest .

Then you will be able to use it as follows:

docker run --rm -p 8080:8080 spring-petclinic-angular:latest

Documentation

The documentation of the Spring Petclinic Angular application is generated by the compodoc tool.

Documentation URL: https://spring-petclinic.github.io/spring-petclinic-angular/

Regenerate the docs folder with compodoc:

npx @compodoc/compodoc@2.0.0 -p tsconfig.doc.json -d docs

Deploy on Web servers

Deploy on Nginx (for Nginx CentOS installation):

  1. Build Angular application:

ng build --prod --base-href=/petclinic/ --deploy-url=/petclinic/

  1. Create sub-directory /petclinic in default nginx directory /usr/share/nginx/html

  2. Copy /dist sub-directory from Angular appication to /usr/share/nginx/html/petclinic

  3. Edit nginx config (nginx.conf file in /etc/nginx/ directory)

server {
	listen       80 default_server;
        root         /usr/share/nginx/html;
        index index.html;

	location /petclinic/ {
                alias /usr/share/nginx/html/petclinic/dist/;
                try_files $uri$args $uri$args/ /petclinic/index.html;
        }
}
  1. Reload nginx: nginx -s reload

  2. Run app in brouser: http://server_name/petclinic/

Deploy on Apache (for Apache CentOS installation):

  1. Build Angular application:

ng build --prod --base-href=/petclinic/ --deploy-url=/petclinic/

  1. Create sub-directory /petclinic in default Apache directory /var/www/html

  2. Go into Angular appication /dist sub-directory and copy all files and sub-dirs from it to /var/www/html/petclinic

  3. Edit Apache config (/etc/https/conf/httpd.conf):

sudo vi /etc/httpd/conf/httpd.conf

Find the Directory /var/www/html> section and change the AllowOverride directive from None to All:

 /etc/httpd/conf/httpd.conf
 . . .
  <Directory /var/www/html>
 . . .
 # 
 # AllowOverride controls what directives may be placed in .htaccess files.
 # It can be "All", "None", or any combination of the keywords:
 # Options FileInfo AuthConfig Limit
 #
 AllowOverride All
 . . .
 </Directory>
 . . .
  1. Save and exit the file and then restart Apache to apply the change:

sudo systemctl restart httpd

  1. Create a .htaccess file in the directory /var/www/html/petclinic

sudo vi /var/www/html/petclinic/.htaccess

Add the following line to the top of the file to activate the RewriteEngine, which instructs Apache to process any rules that follow:

RewriteEngine On  
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]  
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d  
RewriteRule ^ - [L]

# If the requested resource doesn't exist, use index.html
RewriteRule ^ index.html  
  1. Reload Apache:

sudo systemctl restart httpd

  1. Run app in browser: http://server_name/petclinic/

Running unit tests

Run npm test to execute the unit tests interactively via Vitest in jsdom. Run npm run test:ci for a single jsdom pass, or npm run test:coverage to generate HTML and LCOV coverage reports under coverage/.

Running end-to-end tests

Run npm run e2e to execute the end-to-end tests via Playwright. The Playwright config starts the Angular dev server automatically. Install Playwright browsers first with npx playwright install --with-deps.

Linting

Run npm run lint to lint TypeScript and Angular templates with Angular ESLint.

Further help

To get more help on the Angular CLI use npm run ng -- help or visit the Angular CLI documentation.

About

Angular 22 version of the Spring Petclinic sample application (frontend)

Topics

Resources

Stars

217 stars

Watchers

16 watching

Forks

Releases

Packages

Used by

Contributors

Languages