http-proxy-middleware icon indicating copy to clipboard operation
http-proxy-middleware copied to clipboard

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

Open mylnikovD opened this issue 5 years ago • 9 comments
trafficstars

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

mylnikovD avatar May 06 '20 11:05 mylnikovD

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

benknab avatar Aug 20 '20 06:08 benknab

me too

shijunti19 avatar Sep 22 '20 12:09 shijunti19

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`]: '',
    },
}));

eugenehere avatar Dec 14 '20 08:12 eugenehere

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

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

belimposition avatar Jan 29 '21 07:01 belimposition

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 avatar Mar 01 '22 09:03 neodes-h

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

Hope this helps someone.

neodes-h avatar Mar 01 '22 10:03 neodes-h

me too. It worked fine even log error.

taoliujun avatar Jun 20 '22 06:06 taoliujun

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': ''
      }
    })
  );
};

mahdikhashan avatar Feb 21 '23 17:02 mahdikhashan