Skip to content

docs: update proxy wiki #10553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/documentation/stories.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
- [Proxy](stories/proxy)
- [Routing](stories/routing)
- [3rd Party Lib](stories/third-party-lib)
- [Corporate Proxy](stories/using-corporate-proxy)
- [Internationalization (i18n)](stories/internationalization)
- [Serve from Disk](stories/disk-serve)
- [Code Coverage](stories/code-coverage)
Expand Down
64 changes: 55 additions & 9 deletions docs/documentation/stories/proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ We create a file next to our project's `package.json` called `proxy.conf.json` w

You can read more about what options are available [here](https://webpack.js.org/configuration/dev-server/#devserver-proxy).

We can then edit the `package.json` file's start script to be
We can then add the `proxyConfig` option to the serve target:

```json
"start": "ng serve --proxy-config proxy.conf.json",
"architect": {
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "your-application-name:build",
"proxyConfig": "src/proxy.conf.json"
},
```

Now in order to run our dev server with our proxy config, we can simply call `npm start`.
Now in order to run our dev server with our proxy config we can call `ng serve`.

**After each edit to the proxy.conf.json file remember to relaunch the `npm start` process to make your changes effective.**
**After each edit to the proxy.conf.json file remember to relaunch the `ng serve` process to make your changes effective.**

### Rewriting the URL path

Expand Down Expand Up @@ -105,10 +111,16 @@ const PROXY_CONFIG = [
module.exports = PROXY_CONFIG;
```

and make sure to point to the right file
Make sure to point to the right file (`.js` instead of `.json`):

```json
"start": "ng serve --proxy-config proxy.conf.js",
"architect": {
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "your-application-name:build",
"proxyConfig": "src/proxy.conf.js"
},
```

### Bypass the Proxy
Expand All @@ -133,8 +145,42 @@ const PROXY_CONFIG = {
module.exports = PROXY_CONFIG;
```

again, make sure to point to the right file
### Using corporate proxy

```json
"start": "ng serve --proxy-config proxy.conf.js",
If you work behind a corporate proxy, the regular configuration will not work if you try to proxy
calls to any URL outside your local network.

In this case, you can configure the backend proxy to redirect calls through your corporate
proxy using an agent:

```bash
npm install --save-dev https-proxy-agent
```

Then instead of using a `proxy.conf.json` file, we create a file called `proxy.conf.js` with
the following content:

```js
var HttpsProxyAgent = require('https-proxy-agent');
var proxyConfig = [{
context: '/api',
target: 'http://your-remote-server.com:3000',
secure: false
}];

function setupForCorporateProxy(proxyConfig) {
var proxyServer = process.env.http_proxy || process.env.HTTP_PROXY;
if (proxyServer) {
var agent = new HttpsProxyAgent(proxyServer);
console.log('Using corporate proxy server: ' + proxyServer);
proxyConfig.forEach(function(entry) {
entry.agent = agent;
});
}
return proxyConfig;
}

module.exports = setupForCorporateProxy(proxyConfig);
```

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`.
44 changes: 0 additions & 44 deletions docs/documentation/stories/using-corporate-proxy.md

This file was deleted.