Issue
With the angular-cli ng serve local dev server, it's serving all the static files from my project directory.
How can I proxy my AJAX calls to a different server?
Solution
UPDATE 2022
The officially recommended approach is now the one documented here
UPDATE 2017
Better documentation is now available and you can use both JSON and JavaScript based configurations: angular-cli documentation proxy
sample https proxy configuration
{
"/angular": {
"target": {
"host": "github.com",
"protocol": "https:",
"port": 443
},
"secure": false,
"changeOrigin": true,
"logLevel": "info"
}
}
To my knowledge with Angular 2.0 release setting up proxies using .ember-cli file is not recommended. official way is like below
edit
"start"of yourpackage.jsonto look below"start": "ng serve --proxy-config proxy.conf.json",create a new file called
proxy.conf.jsonin the root of the project and inside of that define your proxies like below{ "/api": { "target": "http://api.yourdomai.com", "secure": false } }Important thing is that you use
npm startinstead ofng serve
Read more from here : Proxy Setup Angular 2 cli
Answered By - imal hasaranga perera
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.