From a81aa3b6117848a1c9c99d3b6d0666433b5144e0 Mon Sep 17 00:00:00 2001 From: Leon Radley Date: Tue, 30 Aug 2016 15:37:53 +0200 Subject: [PATCH 1/3] proxy-config documentation --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index ce0178c2d371..5c1014161f94 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ The generated project has dependencies that require **Node 4.x.x and NPM 3.x.x** * [Adding extra files to the build](#adding-extra-files-to-the-build) * [Running Unit Tests](#running-unit-tests) * [Running End-to-End Tests](#running-end-to-end-tests) +* [Proxy To Backend](#proxy-to-backend) * [Deploying the App via GitHub Pages](#deploying-the-app-via-github-pages) * [Linting and formatting code](#linting-and-formatting-code) * [Support for offline applications](#support-for-offline-applications) @@ -186,6 +187,31 @@ Before running the tests make sure you are serving the app via `ng serve`. End-to-end tests are run via [Protractor](https://angular.github.io/protractor/). +### 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 th `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 + +``` +{ + "api/*": { + "target": "http://localhost:3000", + "secure": false + } +} +``` + +and then we edit the `package.json` file's start script to be + +``` +"start": "ng serve --proxy-config proxy.conf.json", +``` + +now run it with `npm start` ### Deploying the app via GitHub Pages From 95eba22c179a8d6adb55a4cdc22ecff60817aa2b Mon Sep 17 00:00:00 2001 From: Leon Radley Date: Wed, 31 Aug 2016 08:45:45 +0200 Subject: [PATCH 2/3] Added link to webpack-dev-server's proxy settings --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5c1014161f94..e462668da058 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,8 @@ with the content } ``` +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 ``` From 180b668de7f38ea872bd0d967fed379566f42dc9 Mon Sep 17 00:00:00 2001 From: Leon Radley Date: Mon, 12 Sep 2016 16:13:45 +0200 Subject: [PATCH 3/3] Fixed proxy path --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e462668da058..4c184f2b25fe 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ with the content ``` { - "api/*": { + "/api": { "target": "http://localhost:3000", "secure": false }