Angular 4为多个域配置代理

问题描述 投票:0回答:1

我使用Angular4以下列方式为域添加了代理,

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

我已经在项目文件夹的根目录中创建了proxy.config.json

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

但是我如何为多个域设置代理?

我想为不同的API调用使用两个不同的域名,

  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
angular
1个回答
1
投票

试试这个:

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

在proxy.conf.js(不是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;

https://stackoverflow.com/a/45666176/6528560相似

© www.soinside.com 2019 - 2024. All rights reserved.