I am busy with a web app that needs to make http requests to a server on my local network. i'm using Angular-cli to build/run my project. When makeing any complex requests i'm running into CORS issues and trying to use the angular-cli proxy to handle those complex requests... I set it up exactly as it's done on the angular-cli github page but it doesn't seem to work. Any idea what i'm doing wrong?
my code:
proxy.conf.json:
{
"/api":{
"target":"http://10.60.160.34/BRMServices/WebEnquiry/",
"secure":false
}
}
from package.json:
"start": "ng serve --proxy-config proxy.conf.json",
a function with a complex request that's supposed to go to the proxy:
postStockTake(stockTakeModel: StockTakeModel) : Observable<Response> {
return this.http.post("/api" + "/StockTake/AddToStockTake", JSON.stringify(stockTakeModel), {headers: this.headers})
.map((res: Response) => res.json())
.catch((error: any) => Observable.throw(error.json().error || 'server error'));
}
I then run the app with npm start instead of ng serve... When it starts to build I see the following in my command prompt console:
> [email protected] start C:\Users\User1\Documents\trade-link\barcode-checker
> ng serve --proxy-config proxy.conf.json
And in my chrome dev tools console I see:
zone.js:1725
POST
http://localhost:4200/api/StockTake/AddToStockTake
405 (Method Not Allowed)
So it's clearly still trying to post to localhost even though I added the local server's IP address in the target value of the proxy.conf file?