Skip to content

Commit cff95a7

Browse files
justinkurtzfilipesilva
authored andcommitted
docs(@angular/cli): add bypass proxy example
1 parent 143a074 commit cff95a7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/documentation/stories/proxy.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,31 @@ and make sure to point to the right file
5656
```json
5757
"start": "ng serve --proxy-config proxy.conf.js",
5858
```
59+
60+
### Bypass the Proxy
61+
62+
If you need to optionally bypass the proxy, or dynamically change the request before it's sent, define the configuration in proxy.conf.js e.g.
63+
64+
```js
65+
const PROXY_CONFIG = {
66+
"/api/proxy": {
67+
"target": "http://localhost:3000",
68+
"secure": false,
69+
"bypass": function (req, res, proxyOptions) {
70+
if (req.headers.accept.indexOf("html") !== -1) {
71+
console.log("Skipping proxy for browser request.");
72+
return "/index.html";
73+
}
74+
req.headers["X-Custom-Header"] = "yes";
75+
}
76+
}
77+
}
78+
79+
module.exports = PROXY_CONFIG;
80+
```
81+
82+
again, make sure to point to the right file
83+
84+
```json
85+
"start": "ng serve --proxy-config proxy.conf.js",
86+
```

0 commit comments

Comments
 (0)