chimurai / http-proxy-middleware

:zap: The one-liner node.js http-proxy middleware for connect, express, next.js and more
MIT License
10.62k stars 824 forks source link

[HPM] Error occurred while trying to proxy request using vpn on windows #436

Open mylnikovD opened 4 years ago

mylnikovD commented 4 years ago

Hello, I'm using react app on localhost:3000 which is proxying to our backend server via OpenConnect vpn. My setup is on windows machine and everything worked fine until some moment when I was doing npm start I've started getting
"[HPM] Error occurred while trying to proxy request ... (ENOTFOUND)" errors. The strange things started here - the backend is reachable and opens without any problem in browser, and restarting my PC is actually helping me to solve this problem, however, reloading PC on every occurrence of this error seems snot very good :)

My guess it's something with windows settings, or maybe with VPN connections in the system, I thought maybe someone encountered with the same thing and can give me a hint

bkiac commented 3 years ago

I get the same [HPM] Error occurred while trying to proxy request ... (ENOTFOUND) with WireGuard VPN. Target is reachable in browser.

shijunti19 commented 3 years ago

me too

eugenehere commented 3 years ago

I get similar error when requesting my proxy server (node.js v14.15.1 + express): Error occured while trying to proxy to: <hostname> Response code: 500. Here is my code:

app.use('/api', createProxyMiddleware({
    target: API_SERVICE_URL,
    pathRewrite: {
        [`^/api`]: '',
    },
}));
belimposition commented 3 years ago

у меня такая же проблема next.js + express

    server.use(
      '/auth-api',
      createProxyMiddleware({
        target: CURRENT_API_URL,
        changeOrigin: true,
        logLevel: 'debug',
        pathRewrite: {
          '^/auth-api': '/',
        },
      }),
    );
neodes-h commented 2 years ago

Is there any update on this? I got the same behavior on MacOS. I am using ClashX as my VPN and config it to be system level proxy but still cannot get it working. My guess is somehow the lower level of http-proxy-middleware ignores VPN so that all the requests got timeout at last.

neodes-h commented 2 years ago

I found a way to solve this problem. https://stackoverflow.com/questions/41832770/node-http-proxy-not-working-behind-proxy

Hope this helps someone.

taoliujun commented 2 years ago

me too. It worked fine even log error.

mahdikhashan commented 1 year ago

It worked for me using v2ray protocol on a mac with V2rayU. Just set the http listen address and port as an agent like bellow and you're good to go:

var HttpsProxyAgent = require('https-proxy-agent');
const { createProxyMiddleware, fixRequestBody } = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(
    '/api',
    createProxyMiddleware({
      target: process.env.REACT_APP_API_URL
      changeOrigin: true,
      secure: false,
      logLevel: "debug",
      onProxyReq: fixRequestBody,
      agent: new HttpsProxyAgent('http://127.0.0.1:1087'),
      headers: {
        'X-Auth-Token': process.env.REACT_APP_API_TOKEN
      },
      pathRewrite: {
        '^/api': ''
      }
    })
  );
};
zqian7531 commented 1 month ago

In the latest version, you need to use curly braces when importing, like this: const { HttpsProxyAgent } = require('https-proxy-agent');