You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you work behind a corporate proxy, the regular [backend proxy](http://github.com/angular/angular-cli#proxy-to-backend) configuration will not work if you try to proxy calls to any URL outside your local network.
4
+
5
+
In this case, you can configure the backend proxy to redirect calls through your corporate proxy using an agent:
6
+
7
+
```bash
8
+
npm install --save-dev https-proxy-agent
9
+
```
10
+
11
+
Then instead of using a `proxy.conf.json` file, we create a file called `proxy.conf.js` with the content
12
+
13
+
```js
14
+
var HttpsProxyAgent =require('https-proxy-agent');
15
+
var proxyConfig = [{
16
+
context:'/api',
17
+
target:'http://your-remote-server.com:3000',
18
+
secure:false
19
+
}];
20
+
21
+
functionsetupForCorporateProxy(proxyConfig) {
22
+
var proxyServer =process.env.http_proxy||process.env.HTTP_PROXY;
and edit the `package.json` file's start script accordingly
37
+
38
+
```json
39
+
"start": "ng serve --proxy-config proxy.conf.js",
40
+
```
41
+
42
+
This way if you have a `http_proxy` or `HTTP_PROXY` environment variable defined, an agent will automatically be added to pass calls through your corporate proxy when running `npm start`.
0 commit comments