Skip to content

Commit 3bc9d76

Browse files
committed
docs: fold corporate proxy into proxy doc
1 parent 28d343e commit 3bc9d76

File tree

3 files changed

+42
-47
lines changed

3 files changed

+42
-47
lines changed

docs/documentation/stories.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
- [Proxy](stories/proxy)
2222
- [Routing](stories/routing)
2323
- [3rd Party Lib](stories/third-party-lib)
24-
- [Corporate Proxy](stories/using-corporate-proxy)
2524
- [Internationalization (i18n)](stories/internationalization)
2625
- [Serve from Disk](stories/disk-serve)
2726
- [Code Coverage](stories/code-coverage)

docs/documentation/stories/proxy.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ We can then add the `proxyConfig` option to the serve target:
2525
"serve": {
2626
"builder": "@angular-devkit/build-angular:dev-server",
2727
"options": {
28-
"browserTarget": "rx-seven-project:build",
28+
"browserTarget": "your-application-name:build",
2929
"proxyConfig": "src/proxy.conf.json"
3030
},
3131
```
@@ -118,7 +118,7 @@ Make sure to point to the right file (`.js` instead of `.json`):
118118
"serve": {
119119
"builder": "@angular-devkit/build-angular:dev-server",
120120
"options": {
121-
"browserTarget": "rx-seven-project:build",
121+
"browserTarget": "your-application-name:build",
122122
"proxyConfig": "src/proxy.conf.js"
123123
},
124124
```
@@ -144,3 +144,43 @@ const PROXY_CONFIG = {
144144

145145
module.exports = PROXY_CONFIG;
146146
```
147+
148+
### Using corporate proxy
149+
150+
If you work behind a corporate proxy, the regular configuration will not work if you try to proxy
151+
calls to any URL outside your local network.
152+
153+
In this case, you can configure the backend proxy to redirect calls through your corporate
154+
proxy using an agent:
155+
156+
```bash
157+
npm install --save-dev https-proxy-agent
158+
```
159+
160+
Then instead of using a `proxy.conf.json` file, we create a file called `proxy.conf.js` with
161+
the following content:
162+
163+
```js
164+
var HttpsProxyAgent = require('https-proxy-agent');
165+
var proxyConfig = [{
166+
context: '/api',
167+
target: 'http://your-remote-server.com:3000',
168+
secure: false
169+
}];
170+
171+
function setupForCorporateProxy(proxyConfig) {
172+
var proxyServer = process.env.http_proxy || process.env.HTTP_PROXY;
173+
if (proxyServer) {
174+
var agent = new HttpsProxyAgent(proxyServer);
175+
console.log('Using corporate proxy server: ' + proxyServer);
176+
proxyConfig.forEach(function(entry) {
177+
entry.agent = agent;
178+
});
179+
}
180+
return proxyConfig;
181+
}
182+
183+
module.exports = setupForCorporateProxy(proxyConfig);
184+
```
185+
186+
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`.

docs/documentation/stories/using-corporate-proxy.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)