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?
http://localhost:4200/address/cities?cityName=&zipCode=2000&languageCode=NL, but I getInternal server erroras a response. If I try the request in my browser directly and replacelocalhost:4200with the actual API url, the request works fine.Internal server erroris the reply you get when required parameters are missing, so I assume that's the problem.GET /address/citiesand using your exact proxy configuration I got the same proxy console output, but I was successfully able to pass query parameterscityName,zipCode, andlanguageCodeusing the exact URL you are using in your GET request. Your proxy configuration is correct. You will need to debug the response from the server, for example in your URLcityNamedoesn't have a value, could that cause a 500 error from the API? Does this API support CORS? It's hard to help without knowing the exact error happening.localhost:4200with the API url it works just fine, even with an emptycityNamevalue. I don't know enough about their API to really answer anything else, so I think I'll have to find another way of solving the issue. Thanks for the help though./addresspart from the target. So instead of"target": "https://api-url.com/address/",it has to be"target": "https://api-url.com/".