0

I have added a proxy for a domain in the following way using Angular4,

/admin/rest/v1.0/pays/pay?sort=regTimeStamp,desc

And i have created the proxy.config.json in the root of the project folder.

{
    "/admin/*" : {
    "target": "https://uat.global.com:8080",
    "secure": false,
    "logLevel": "debug",
    "changeOrigin": true
  }

But how do i set proxy for multiple domains?

i want to use two different domain names for different API calls,

  1. https://uat.global.com:8080/admin/rest/v1.0/pays/pay?sort=regTimeStamp,desc
  2. https://uats.global.com:8081/admin/rest/v1.0/upi/call?sort=regTimeStamp,desc
vishnu
  • 4,377
  • 15
  • 52
  • 89

1 Answers1

3

Try this:

 "start": "ng serve --proxy-config proxy.conf.js --base-href /"

In proxy.conf.js (not json!):

 const PROXY_CONFIG = {
     "/api/*": {
         target: https://www.mydefaulturl.com,
         router: function (req) {
             // some condition here
             var target = 'https://www.myrewrittenurl.com'; // or some custom code
             return target;
         },
         changeOrigin: true,
         secure: false
     }
 };

 module.exports = PROXY_CONFIG;

Similar to https://stackoverflow.com/a/45666176/6528560

Oleksandr Poshtaruk
  • 2,062
  • 15
  • 18