Skip to content
Closed
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,11 @@ __Service Proxies:__

The `serve` command can add some proxies to the http server. These proxies are useful if you are developing in the browser and you need to make calls to an external API. With this feature you can proxy request to the external api through the ionic http server preventing the `No 'Access-Control-Allow-Origin' header is present on the requested resource` error.

In the `ionic.project` file you can add a property with an array of proxies you want to add. The proxies are object with two properties:
In the `ionic.project` file you can add a property with an array of proxies you want to add. The proxies are object with the following properties:

* `path`: string that will be matched against the beginning of the incoming request URL.
* `proxyUrl`: a string with the url of where the proxied request should go.
* `proxyNoAgent`: (optional) true/false, if true opts out of connection pooling, see [HttpAgent](http://nodejs.org/api/http.html#http_class_http_agent)

```json
{
Expand Down
6 changes: 5 additions & 1 deletion lib/ionic/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ IonicTask.prototype.start = function(ionic) {
for(var x=0; x<this.proxies.length; x++) {
var proxy = this.proxies[x];

app.use(proxy.path, proxyMiddleware(url.parse(proxy.proxyUrl)));
var opts = url.parse(proxy.proxyUrl);
if(proxy.proxyNoAgent)
opts.agent = false;

app.use(proxy.path, proxyMiddleware(opts));
console.log('Proxy added:'.green.bold, proxy.path + " => " + url.format(proxy.proxyUrl));
}
}
Expand Down