【问题标题】:How to setup http-proxy-middleware using same endpoint for different api url | React | Axios如何为不同的 api url 使用相同的端点设置 http-proxy-middleware |反应 |爱讯
【发布时间】:2020-04-30 11:51:57
【问题描述】:

我正在尝试为具有相同端点的多个 API URL 设置 http-proxy-middleware,但它不起作用。

setupProxy.php

const proxy =require("http-proxy-middleware");

module.exports = function(app)
{
  app.use(proxy("rest/V1/orders",{target:"http://example.net/",changeOrigin:true}));
  app.use(proxy("rest/V1/orders",{target:"http://example.org/",changeOrigin:true}));
  app.use(proxy("rest/V1/orders",{target:"http://example.com/",changeOrigin:true}));
}

【问题讨论】:

    标签: reactjs http-proxy-middleware


    【解决方案1】:

    对 https-proxy-middleware 使用 this package

    为了设置在src目录下创建setupProxy.js

    参考文档以获取示例代码

    【讨论】:

    • 嗨 iam 仅使用 https-proxy-middleware 包我的问题是针对具有相同端点的多个 API URL,不能按预期工作请建议,setupProxy.php 中的 PFA 代码
    • 具有相同端点的多个 API URL 意味着 https://ex.com/testhttps://ex1.com/test 就像这些......因为我无法在评论中编写实体代码,我可以根据您的需要编辑我的答案跨度>
    • 具有相同端点的多个 API URL 意味着 ex.com/testex1.com/test 就像这些。正确,我也需要。请就此提出建议。
    • 如果你是这样获取的,你首先需要一个代理,你可以直接从客户端调用端点
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多