# Usage in Projects

`@dsivd/prestations-ng` should be used in a project, such as a prestation, in the way described below.

You'll find an exemple of integration in the demo project, [Skeleton](https://portail.etat-de-vaud.ch/outils/git/projects/CYBSDK/repos/skeleton/browse).

## Changes to `angular.json`

The `index.html` is provided by `@dsivd/prestations-ng`. You can use it from the
`node_modules` directly with:

```diff
"architect": {
  "build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
      "outputPath": "dist",
-     "index": "src/index.html"
+     "index": "./node_modules/@dsivd/prestations-ng/index.html",
```

As we're using an `index.html` agnostic from the application, you must specify the `baseHref`.

```diff
"production": {
  ...
  "progress": false,
+ "baseHref": "#context-path#"
}
```

For testing you must have `baseHref` matching what is in your `proxy.conf.json` (see below).

```diff
"serve": {
  "builder": "@angular-devkit/build-angular:dev-server",
  "options": {
    "buildTarget": "skeleton:build",
    "host": "0.0.0.0",
    "proxyConfig": "proxy.conf.json",
+   "baseHref": "/pub/101016/"
  },
},
```

## Adding a `proxy.conf.json`

To seamlessly integrate the Angular frontend with the Java backend, it's recommended
to use a `proxy.conf.json` configuration.

The `target` must contain the port on which the backend api (`prestations-be`) is running.

```json
{
    "/pub/101016/api/*": {
        "target": "http://localhost:16400",
        "changeOrigin": true,
        "secure": false,
        "pathRewrite": {
            "^/api": ""
        }
    },
    "/pub/101016/*": {
        "target": "http://localhost:4200",
        "changeOrigin": true,
        "secure": false,
        "logLevel": "debug",
        "pathRewrite": {
            "^/pub/101016": ""
        }
    }
}
```

The configuration should be added in the `angular.json` under the `serve` key.

```diff
"serve": {
  "builder": "@angular-devkit/build-angular:dev-server",
  "options": {
    "buildTarget": "skeleton:build",
    "host": "0.0.0.0",
+   "proxyConfig": "proxy.conf.json",
    "baseHref": "/pub/101016/"
  },
},
```
