Skip to content

Commit 79288cf

Browse files
leonfilipesilva
authored andcommitted
chore(docs): proxy-config documentation
Close #1896
1 parent ce03088 commit 79288cf

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The generated project has dependencies that require **Node 4.x.x and NPM 3.x.x**
4141
* [Adding extra files to the build](#adding-extra-files-to-the-build)
4242
* [Running Unit Tests](#running-unit-tests)
4343
* [Running End-to-End Tests](#running-end-to-end-tests)
44+
* [Proxy To Backend](#proxy-to-backend)
4445
* [Deploying the App via GitHub Pages](#deploying-the-app-via-github-pages)
4546
* [Linting and formatting code](#linting-and-formatting-code)
4647
* [Support for offline applications](#support-for-offline-applications)
@@ -192,6 +193,33 @@ Before running the tests make sure you are serving the app via `ng serve`.
192193

193194
End-to-end tests are run via [Protractor](https://angular.github.io/protractor/).
194195

196+
### Proxy To Backend
197+
Using the proxying support in webpack's dev server we can highjack certain urls and send them to a backend server.
198+
We do this by passing a file to `--proxy-config`
199+
200+
Say we have a server running on `http://localhost:3000/api` and we want all calls th `http://localhost:4200/api` to go to that server.
201+
202+
We create a file next to projects `package.json` called `proxy.conf.json`
203+
with the content
204+
205+
```
206+
{
207+
"/api": {
208+
"target": "http://localhost:3000",
209+
"secure": false
210+
}
211+
}
212+
```
213+
214+
You can read more about what options are available here [webpack-dev-server proxy settings](https://webpack.github.io/docs/webpack-dev-server.html#proxy)
215+
216+
and then we edit the `package.json` file's start script to be
217+
218+
```
219+
"start": "ng serve --proxy-config proxy.conf.json",
220+
```
221+
222+
now run it with `npm start`
195223

196224
### Deploying the app via GitHub Pages
197225

0 commit comments

Comments
 (0)