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
1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.