https://github.com/angular/angular-cli#proxy-to-backend here is an instruction how to do proxying to backend. I did everything step by step and still requests aren\'t proxie
Could you try with this one:
{
"/api": {
"target": "http://url.com",
"secure": false,
"pathRewrite": {"^/api" : ""}
}
}
It works for me,
** NG Live Development Server is running on http://localhost:4200. **
10% building modules 3/3 modules 0 active[HPM] Proxy created: /api -> http://ec2-xx-xx-xx-xx.ap-south-1.compute.amazonaws.com
[HPM] Proxy rewrite rule created: "^/api" ~> ""
This was close to working for me. Also had to add
"changeOrigin": true,
full proxy.conf.json shown below:
{
"/proxy/*": {
"target": "https://url.com",
"secure": false,
"changeOrigin": true,
"logLevel": "debug",
"pathRewrite": {"^/proxy" : ""}
}
}
On MAC this works for me
Angular 4 running localhost: http://localhost:4200/
In package.json
"start": "ng serve --proxy-config proxy.config.json",
In proxy.config.json
Where our-company-server would be replaced by off-site URL
{
"/v1": {
"target": "https://our-company-server.com:7002",
"secure": false,
"logLevel": "debug"
}
}
Where an angular GET request would be...
this.http.get('/v1/dashboard/client', options).map...
// options are headers, params, etc...
// then .map the observable in this case.
I had to make a small adjustment based on the above answers, although it seems a bit odd looking at the config now.
This is my proxy.conf.json shown below:
{
"/api/*": {
"target": "https://url.com",
"secure": false,
"changeOrigin": true,
"logLevel": "debug",
"pathRewrite": {"^/api" : "http://url.com/api"}
}
}
Basically, I rewrote the path completely. And it works now.
For those having a custom localhost domain, refer to this solution
{
"/api/*": {
"target": "http://backend.site.example",
"secure": false,
"changeOrigin": true,
"pathRewrite": {
"^/api": "http://backend.site.example/api"
}
}
}
Proxy attribute pathRewrite should be added in the proxy.conf.json.
See the example below.
{
"/services/*": {
"target": "http://yoururl.com",
"secure": false,
"changeOrigin" : true,
"pathRewrite": {
"^/services" : ""
}
}
}
and run ng serve --proxy-config proxy.conf.json Surely it will work.