【问题标题】:Specifying proxy for http-proxy-middleware为 http-proxy-middleware 指定代理
【发布时间】:2019-03-19 11:02:21
【问题描述】:

我有一个用于连接多个微服务的前端的 nodeJS 项目。当我们进行最终部署时,我们实际上将构建的 JS 和 HTML 与后端一起部署在 WAR 文件中。

但是,对于开发,我们使用http-proxy-middleware,因此我们能够在前端进行快速更改和编辑并查看结果。

不过,今天,我希望能够看到连接离开 NODE-JS 并进入我们的微服务。

具体来说,我想通过 fiddler(它是一个通常在端口 8888 上运行的 http 代理)来传输它们。

有人知道这样做吗?

我尝试设置例如以下但不影响传出连接:

npm 配置设置代理http://localhost:8888

【问题讨论】:

    标签: node.js proxy fiddler http-proxy-middleware


    【解决方案1】:

    npm config set proxy http://localhost:8888用于配置NPM通过代理下载包。

    您需要连接到 fiddler 的 HTTP 代理而不是您通常的后端,并使用相关的 HTTP 标头进行代理。

    所以请求看起来像

    http.get ({
        host: '127.0.0.1',
        port: 8888,
        path: 'http://actual.backend/url'
    }, function (response) {
        console.log (response);
    });
    

    【讨论】:

      【解决方案2】:

      好吧,我的问题的答案是use fiddler as a reverse proxy

      https://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/UseFiddlerAsReverseProxy

      我偶然发现了它。我想也许我不能拦截所有请求,但我可以将我的端点设置为提琴手。

      我这样做了,并在提琴手中看到了来自 Fiddler Echo Service 的回复。

      它基本上显示的页面类似于:

      Fiddler Echo Service
      
      PUT /abc-service/initialize HTTP/1.1
      accept-language: en-AU,en;q=0.9,el;q=0.8,en-NZ;q=0.7,en-US;q=0.6,en-GB;q=0.5
      accept-encoding: gzip, deflate, br
      accept: */*
      postman-token: 0466cca5-21f9-67ab-be05-5227ef667fe4
      user-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36
      origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
      cache-control: no-cache
      content-length: 0
      connection: close
      host: localhost:8889   
      X-Tenant-Id: abc  
      X-Forwarded-Proto: http
      X-Forwarded-Force-Http-Protocol: true
      X-Forwarded-Prefix: abc-service
      
      This page returned a HTTP/200 response 
      Originating Process Information: node:15044
      
      --------------------------------------------------------------------------------
      •To configure Fiddler as a reverse proxy instead of seeing this page, see Reverse Proxy Setup ( https://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/UseFiddlerAsReverseProxy )
      •You can download the FiddlerRoot certificate
      

      【讨论】:

        猜你喜欢
        • 2021-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-18
        • 2017-08-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多