最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Zero response through http-proxy-middleware - Stack Overflow

programmeradmin3浏览0评论

I am trying to debug a proxy in Express, using http-proxy-middleware, but no matter what I do I get absolutely zero response. The endpoint sends the response but it is never returned by the proxy and the onProxyRes event is never triggered. Also the endpoint can be accessed directly through curl, Insomnia, fetch API and request-promise and is in use as an API for our customers.

Even with a setup as simple as:

app.use('/api', proxy({
  target: '',
  changeOrigin: true
});

I get absolutely zero response, except for a ECONNRESET after timeout. Any suggestions?

I am trying to debug a proxy in Express, using http-proxy-middleware, but no matter what I do I get absolutely zero response. The endpoint sends the response but it is never returned by the proxy and the onProxyRes event is never triggered. Also the endpoint can be accessed directly through curl, Insomnia, fetch API and request-promise and is in use as an API for our customers.

Even with a setup as simple as:

app.use('/api', proxy({
  target: 'https://my.secret.endpoint',
  changeOrigin: true
});

I get absolutely zero response, except for a ECONNRESET after timeout. Any suggestions?

Share Improve this question asked Sep 11, 2018 at 7:31 ViggoVViggoV 2,1732 gold badges20 silver badges22 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

Heureka! I found the answer I was looking for! The offending party was (in my case) the express.urlencoded() middleware, which does some trickery that ultimately messes up the proxy. This can be resolved by applying the offending middleware after the proxy. Other middleware that might do this include cookie-parserand bodyParser (both of which are deprecated).

More on the issue here: https://github./chimurai/http-proxy-middleware/issues/40

ViggoV
You need to disable the SSL when the target is https.

Like as this:

app.use('/api', proxy({
  target: 'https://my.secret.endpoint',
  changeOrigin: true,
  secure: false
});

Another solution for anyone ing here with the same issue but did not solve it.

In proxy configuration make sure you are matching any path with double ** not only *

const proxy = require("http-proxy-middleware");
module.exports = function(app) {
  app.use(proxy("/api/**", { // https://github./chimurai/http-proxy-middleware
    target: "http://localhost:5000",
    secure: false
  }));
};

For more check this reference

发布评论

评论列表(0)

  1. 暂无评论