@@ -25,7 +25,7 @@ We can then add the `proxyConfig` option to the serve target:
25
25
"serve" : {
26
26
"builder" : " @angular-devkit/build-angular:dev-server" ,
27
27
"options" : {
28
- "browserTarget" : " rx-seven-project :build" ,
28
+ "browserTarget" : " your-application-name :build" ,
29
29
"proxyConfig" : " src/proxy.conf.json"
30
30
},
31
31
```
@@ -118,7 +118,7 @@ Make sure to point to the right file (`.js` instead of `.json`):
118
118
"serve" : {
119
119
"builder" : " @angular-devkit/build-angular:dev-server" ,
120
120
"options" : {
121
- "browserTarget" : " rx-seven-project :build" ,
121
+ "browserTarget" : " your-application-name :build" ,
122
122
"proxyConfig" : " src/proxy.conf.js"
123
123
},
124
124
```
@@ -144,3 +144,43 @@ const PROXY_CONFIG = {
144
144
145
145
module.exports = PROXY_CONFIG;
146
146
```
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 ` .
0 commit comments