Skip to content

Commit 391fc0d

Browse files
sinediedMRHarrison
authored andcommitted
docs(proxy): add documentation for corporate proxy configuration with backend proxy (angular#4041) (angular#4070)
Fix angular#4041
1 parent 75493b1 commit 391fc0d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Using corporate proxy
2+
3+
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+
function setupForCorporateProxy(proxyConfig) {
22+
var proxyServer = process.env.http_proxy || process.env.HTTP_PROXY;
23+
if (proxyServer) {
24+
var agent = new HttpsProxyAgent(proxyServer);
25+
console.log('Using corporate proxy server: ' + proxyServer);
26+
proxyConfig.forEach(function(entry) {
27+
entry.agent = agent;
28+
});
29+
}
30+
return proxyConfig;
31+
}
32+
33+
module.exports = setupForCorporateProxy(proxyConfig);
34+
```
35+
36+
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

Comments
 (0)