I need to add a proxy config to make GET requests to a webservice running on another domain (I'm testing on localhost:4200). I've added the following proxy.conf.json
file to the root of the project
{
"/address/*": {
"target": "https://api-url.com/address/",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
and added the --proxy-config=proxy.conf.json
flag to the ng serve
command in package.json
. My GET request is pretty simple;
const url = `/address/cities?cityName=&zipCode=2000&languageCode=NL`;
const result = await fetch(url, {
method: 'GET'
});
return await result.json();
I can see the proxy works as [HPM] GET /address/cities?cityName=&zipCode=2000&languageCode=NL -> https://api-url.com/address/
gets logged to the terminal, but the actual request doesn't work as nothing after /address/
is proxied. Is it at all possible to pass the URL params to the proxy?
As was posted in one of the comments the answer is to remove /address
from the target.
{
"/address/*": {
"target": "https://api-url.com/",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
We also had an issue with the URL parameters not being proxied correctly if the /
was missing at the end of the target.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With