I have an entry in my proxy config json, meaning - I have an API base path, that matches one of my application's routes.
I need to route to https://localhost:3000/my-api-route
But what happens is that the proxy.json catches the request and serve it to the server as an API call.
The proxy.json:
"/my-api-route":{
"target":"https://my.domain.com",
"secure":true,
"logLevel":"debug",
"changeOrigin":true
},
CodePudding user response:
You should not have both the same. Because proxy.conf.json
file instructs Angular to proxy the request.
CodePudding user response:
So I found the answer... You can declare the proxy as a JSON or JS file. If you use a JS file, you can add a bypass function in which you can skip requests with 'html' string contained in their header.
For example:
bypass: function (req, res, proxyOptions) {
if (req?.headers?.accept?.indexOf("html") !== -1) {
console.log("Skipping proxy for browser request.");
return "/index.html";
}
}
You can read more about it, here: https://angular.io/guide/build#bypass-the-proxy