|
| 1 | +# Spring Petclinic Angular |
| 2 | + |
| 3 | +[](https://github.com/spring-petclinic/spring-petclinic-angular/actions/workflows/angular-ci.yml) |
| 4 | + |
| 5 | +## Angular frontend for Spring Petclinic |
| 6 | + |
| 7 | +Warning: **client only**. |
| 8 | + Use REST API from backend [spring-petclinic-rest project](https://github.com/spring-petclinic/spring-petclinic-rest) |
| 9 | + You need start backend server before start frontend application. |
| 10 | + |
| 11 | +## Screenshot |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +1. Update angular-cli to latest version (8.0.3 current) |
| 19 | +as described on [angular-cli github readme.md](https://github.com/angular/angular-cli#updating-angular-cli) |
| 20 | + |
| 21 | +```` |
| 22 | +npm uninstall -g angular-cli @angular/cli |
| 23 | +npm cache clean |
| 24 | +npm install -g @angular/cli@latest |
| 25 | +```` |
| 26 | +Clone project from github |
| 27 | +```` |
| 28 | +git clone https://github.com/spring-petclinic/spring-petclinic-angular.git |
| 29 | +```` |
| 30 | +Install local project package |
| 31 | +```` |
| 32 | +npm install --save-dev @angular/cli@latest |
| 33 | +if npm version > 5.0 delete package-lock.json file ( bug in npm 5.0 - this file prevent correct packages install) |
| 34 | +npm install |
| 35 | +```` |
| 36 | + |
| 37 | +Now project use Angular CLI v.8.0.3 and Angular v.8.0.1 |
| 38 | +You can see current dependencies in [package.json](package.json) file. |
| 39 | + |
| 40 | +## Development server |
| 41 | + |
| 42 | +Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. |
| 43 | + |
| 44 | +## Code scaffolding |
| 45 | + |
| 46 | +Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|module`. |
| 47 | + |
| 48 | +## Build |
| 49 | + |
| 50 | +Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build. |
| 51 | + |
| 52 | +You can also build the application in a dedicated docker image using the provided `Dockerfile` as follows: |
| 53 | + |
| 54 | +``` |
| 55 | +docker build -t spring-petclinic-angular:latest . |
| 56 | +``` |
| 57 | + |
| 58 | +Then you will be able to use it as follows: |
| 59 | + |
| 60 | +``` |
| 61 | +docker run --rm -p 8080:8080 spring-petclinic-angular:latest |
| 62 | +``` |
| 63 | + |
| 64 | +## Documentation |
| 65 | + |
| 66 | +The documentation of the Spring Petclinic Angular application is generated by the [compodoc](https://compodoc.app) tool. |
| 67 | + |
| 68 | +Documentation URL: [https://spring-petclinic.github.io/spring-petclinic-angular/](https://spring-petclinic.github.io/spring-petclinic-angular/) |
| 69 | + |
| 70 | +Regenerate the `docs` folder with [compodoc](https://compodoc.app): |
| 71 | +``` |
| 72 | +compodoc -p src/tsconfig.app.json -d docs |
| 73 | +``` |
| 74 | + |
| 75 | +## Deploy on Web servers |
| 76 | + |
| 77 | +### Deploy on Nginx (for Nginx CentOS installation): |
| 78 | + |
| 79 | +1. Build Angular application: |
| 80 | + |
| 81 | + ng build --prod --base-href=/petclinic/ --deploy-url=/petclinic/ |
| 82 | + |
| 83 | +2. Create sub-directory **/petclinic** in default nginx directory **/usr/share/nginx/html** |
| 84 | + |
| 85 | +3. Copy **/dist** sub-directory from Angular appication to **/usr/share/nginx/html/petclinic** |
| 86 | + |
| 87 | +4. Edit nginx config (nginx.conf file in /etc/nginx/ directory) |
| 88 | + |
| 89 | +``` |
| 90 | +server { |
| 91 | + listen 80 default_server; |
| 92 | + root /usr/share/nginx/html; |
| 93 | + index index.html; |
| 94 | +
|
| 95 | + location /petclinic/ { |
| 96 | + alias /usr/share/nginx/html/petclinic/dist/; |
| 97 | + try_files $uri$args $uri$args/ /petclinic/index.html; |
| 98 | + } |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +5. Reload nginx: **nginx -s reload** |
| 103 | + |
| 104 | +6. Run app in brouser: http://server_name/petclinic/ |
| 105 | + |
| 106 | +### Deploy on Apache (for Apache CentOS installation): |
| 107 | + |
| 108 | +1. Build Angular application: |
| 109 | + |
| 110 | +ng build --prod --base-href=/petclinic/ --deploy-url=/petclinic/ |
| 111 | + |
| 112 | +2. Create sub-directory **/petclinic** in default Apache directory **/var/www/html** |
| 113 | + |
| 114 | +3. Go into Angular appication **/dist** sub-directory and copy all files and sub-dirs from it to **/var/www/html/petclinic** |
| 115 | + |
| 116 | +4. Edit Apache config (/etc/https/conf/httpd.conf): |
| 117 | + |
| 118 | +sudo vi /etc/httpd/conf/httpd.conf |
| 119 | + |
| 120 | +Find the Directory /var/www/html> section and change the AllowOverride directive from None to All: |
| 121 | +``` |
| 122 | + /etc/httpd/conf/httpd.conf |
| 123 | + . . . |
| 124 | + <Directory /var/www/html> |
| 125 | + . . . |
| 126 | + # |
| 127 | + # AllowOverride controls what directives may be placed in .htaccess files. |
| 128 | + # It can be "All", "None", or any combination of the keywords: |
| 129 | + # Options FileInfo AuthConfig Limit |
| 130 | + # |
| 131 | + AllowOverride All |
| 132 | + . . . |
| 133 | + </Directory> |
| 134 | + . . . |
| 135 | +``` |
| 136 | +5. Save and exit the file and then restart Apache to apply the change: |
| 137 | + |
| 138 | +sudo systemctl restart httpd |
| 139 | + |
| 140 | +6. Create a .htaccess file in the directory **/var/www/html/petclinic** |
| 141 | + |
| 142 | +sudo vi /var/www/html/petclinic/.htaccess |
| 143 | + |
| 144 | +Add the following line to the top of the file to activate the RewriteEngine, which instructs Apache to process any rules that follow: |
| 145 | +``` |
| 146 | +RewriteEngine On |
| 147 | +# If an existing asset or directory is requested go to it as it is |
| 148 | +RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] |
| 149 | +RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d |
| 150 | +RewriteRule ^ - [L] |
| 151 | +
|
| 152 | +# If the requested resource doesn't exist, use index.html |
| 153 | +RewriteRule ^ index.html |
| 154 | +``` |
| 155 | +7. Reload Apache: |
| 156 | + |
| 157 | +sudo systemctl restart httpd |
| 158 | + |
| 159 | +8. Run app in browser: http://server_name/petclinic/ |
| 160 | + |
| 161 | +## Running unit tests |
| 162 | + |
| 163 | +Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). |
| 164 | + |
| 165 | +## Running end-to-end tests |
| 166 | + |
| 167 | +Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). |
| 168 | +Before running the tests make sure you are serving the app via `ng serve`. |
| 169 | + |
| 170 | +## Further help |
| 171 | + |
| 172 | +To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). |
0 commit comments