Martin Randall
Martin Randall

Reputation: 746

Use equivalent of proxy-config option in ng server to run ng e2e

I'm using the proxy-config as described in other articles to redirect calls to in my Angular application to my back-end API. I use the following as my proxy.conf.json file:-

{
  "/comparison/api": {
    "target": "http://localhost:8080",
    "secure": false,
    "changeOrigin": true
  }
}

This works great, redirecting API calls to my Node/Express stub API service.

When I come to run E2E tests using the Angular CLI, there is no --proxy-config option. Does anyone know how I can set-up the same proxy redirect in the E2E Protractor tests?

Upvotes: 4

Views: 3433

Answers (1)

Raj Sahoo
Raj Sahoo

Reputation: 496

Right now e2e doesn't support --proxy-config as an option. It's part of Nice to Have list. ref - https://github.com/angular/angular-cli/issues/6358

Here is the workaround for now.

e2e uses ng serve at the back and ng serve can be configured to use a proxy.

Modify the serve options in the angular.json file and add proxyConfig.

"serve": {
           "builder": "@angular-devkit/build-angular:dev-server",
           "options": {
                 "browserTarget": "ChangeManagementPortal:build",
                 "proxyConfig": "proxy.conf.json"  
                }

Now ng e2e will run with the proxy redirect.

Upvotes: 10

Related Questions