微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NodeJS http-proxy-middleware 停止转发

如何解决NodeJS http-proxy-middleware 停止转发

我是 Node 的新手,尤其是 http-proxy-middleware,所以我不确定要提供多少信息以及提供哪些信息。我的中间件服务器过去常常接受请求并将它们转发到另一个 Java 服务器并向原始调用者提供响应。但是,它不再转发到 Java 服务器。不过,Java 服务器确实会响应直接请求。我相信这与我们将 Java 服务器从 HTTPS 服务器更改为 HTTP 相关,因为这是更改的关键。然而,我想我告诉了代理中间件它需要的一切。

我通过 DEBUG=express-http-proxy 启用了调试

我的中间件托管在 https://localhost:8080,关键 URI 是 /sprint-cost-recovery。

我的日志显示

2021-02-06T05:46:36.693Z [app.js] debug: Route: /sprint-cost-recovery: Forwarding to http://localhost:8447
  express-http-proxy [start proxy] / +0ms
  express-http-proxy {
  express-http-proxy   limit: '2mb',express-http-proxy   proxyReqPathResolver: [Function: proxyReqPathResolver],express-http-proxy   proxyReqOptDecorator: undefined,express-http-proxy   proxyReqBodyDecorator: undefined,express-http-proxy   userResDecorator: undefined,express-http-proxy   userResHeaderDecorator: undefined,express-http-proxy   proxyErrorHandler: [Function: proxyErrorHandler],express-http-proxy   filter: undefined,express-http-proxy   parseReqBody: true,express-http-proxy   preserveHostHdr: true,express-http-proxy   memoizeHost: false,express-http-proxy   reqBodyEncoding: 'utf-8',express-http-proxy   skipToNextHandlerFilter: undefined,express-http-proxy   headers: undefined,express-http-proxy   preserveReqSession: undefined,express-http-proxy   https: false,express-http-proxy   port: undefined,express-http-proxy   reqAsBuffer: undefined,express-http-proxy   timeout: undefined,express-http-proxy   stream: true
  express-http-proxy } +0ms
  express-http-proxy proxy request options: {
  headers: {
    host: 'localhost:8080','user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0',accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8','accept-language': 'en-US,en;q=0.5','accept-encoding': 'gzip,deflate,br',cookie: 'foo=bar; connect.sid=***; access_token=*****','upgrade-insecure-requests': '1',pragma: 'no-cache','cache-control': 'no-cache',connection: 'close'
  },method: 'GET',path: '/',params: { '0': '' }
} +0ms
  express-http-proxy Request options (after processing): { headers: { host: 'localhost:8080',cookie: 'foo=bar; connect.sid=****; access_token=****',connection: 'close' },host: 'localhost',port: '8447' } +0ms
2021-02-06T05:46:36.697Z [app.js] debug: Route: /sprint-cost-recovery: proxyReqPathResolver() function reached
2021-02-06T05:46:36.697Z [app.js] debug: Route: /sprint-cost-recovery: proxyReqPathResolver(): result=/sprint-cost-recovery
  express-http-proxy resolved proxy path: /sprint-cost-recovery +0ms
2021-02-06T05:46:36.830Z [app.js] debug: Common Route: Incoming request originalUrl:/assets/js/w3ds-5-4-0.js
2021-02-06T05:46:36.830Z [app.js] debug: Common Route: Incoming request prevIoUs Url:https://localhost:8080/sprint-cost-recovery

config.sprint_cost_recovery_client_host=http://localhost:8447 config.sprint_cost_recovery_server_host=http://localhost:8448

我的路由片段是:

    app.use('/sprint-cost-recovery*',ensureAuthenticated,function (req,res,next) {
            logger.debug('Route: /sprint-cost-recovery: Forwarding to '+config.sprint_cost_recovery_client_host);
            next();
        },forward_proxy(config.sprint_cost_recovery_client_host,{
            limit: '2mb',memoizeHost: false,preserveHostHdr: true,https: false,secure: false,proxyErrorHandler: function (err,next) {
                util.inspect(err);
                next();
            },proxyReqPathResolver: req => {
                logger.debug('Route: /sprint-cost-recovery: proxyReqPathResolver() function reached');
                util.inspect(req.originalUrl);
                util.inspect(req.hostname);
                util.inspect(req.https_port);
                const result = url.parse(req.originalUrl).path;
                logger.debug('Route: /sprint-cost-recovery: proxyReqPathResolver(): result=' + result);
                return result;
            }
        })
    );

我愿意接受猜测。顺便说一句,有谁知道是否有用 Java 编写的中间件/表达等价物?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。