I'm using angular-cli, running project from localhost:4200 and trying to get server request from myurl:8080. This isn't working for some reason, have tried all the options but none helped.
Here is my proxy.config.json file:
{
"/myservice/*": {
"target": "http://myurl:8080",
"secure": false,
"changeOrigin": true,
"logLevel": "debug",
"pathRewrite": {"^/myservice" : ""}
}
}
A simple http.get :
private Url = 'http://myurl:8080/myservice/list/getlist';
headers = new Headers({ 'Access-Control-Allow-Origin': '*' });
options = new RequestOptions({ headers: this.headers, withCredentials: true});
getList (): Observable<any> {
return this.http.get(this.Url, this.options)
.map(this.extractData)
.catch(this.handleError);
}
The browser result is:
403 (Forbidden). Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 403.
If I just surf to http://myurl:8080/myservice/list/getlist I will get the JSON result. Did any one made it worked?
after npm start
@Angular/cli is writing
Proxy created: /myservice -> http://myurl:8080
[HPM] Proy rewrite rule create "^/myservice" ~"
[HPM] Subscribed to http-proxy events: ['error', 'close']
Is that normal?