2017-02-13 12:41:05 +00:00

29 lines
816 B
Markdown

# Proxy To Backend
Using the proxying support in webpack's dev server we can highjack certain urls and send them to a backend server.
We do this by passing a file to `--proxy-config`
Say we have a server running on `http://localhost:3000/api` and we want all calls to `http://localhost:4200/api` to go to that server.
We create a file next to projects `package.json` called `proxy.conf.json`
with the content
```json
{
"/api": {
"target": "http://localhost:3000",
"secure": false
}
}
```
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)
and then we edit the `package.json` file's start script to be
```json
"start": "ng serve --proxy-config proxy.conf.json",
```
now run it with `npm start`