Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular proxy config; proxying URL get parameters

Tags:

proxy

angular

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?

like image 790
Alex Avatar asked Oct 20 '25 16:10

Alex


1 Answers

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.

like image 113
Maximilian Liesegang Avatar answered Oct 22 '25 05:10

Maximilian Liesegang