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

Cannot override options in the `onProxyReq` method.

Open ghost opened this issue 2 years ago • 2 comments
trafficstars

Checks

Describe the bug (be clear and concise)

Update the ip agent address dynamically on each request, but it didn't work

Step-by-step reproduction instructions

app.use(
  '/',
  createProxyMiddleware({
    target: 'https://ip.tool.lu/',
    changeOrigin: true,
    followRedirects: true,
    agent: new HttpsProxyAgent({
      proxy: getRandomAgentProxy(),
    }),
    onProxyReq: (proxyReq, req, res, options) => {
      // Update the ip agent address dynamically on each request
      options.agent =  new HttpsProxyAgent({
        proxy: getRandomAgentProxy(),
      });
    }
  }),
);

Expected behavior (be clear and concise)

Hope to update the agent ip dynamically

How is http-proxy-middleware used in your project?

basic express demo.

What http-proxy-middleware configuration are you using?

app.use(
  '/',
  createProxyMiddleware({
    target: 'https://ip.tool.lu/',
    changeOrigin: true,
    followRedirects: true,
    agent: new HttpsProxyAgent({
      proxy: getRandomAgentProxy(),
    }),
    onProxyReq: (proxyReq, req, res, options) => {
      // Update the ip agent address dynamically on each request
      options.agent =  new HttpsProxyAgent({
        proxy: getRandomAgentProxy(),
      });
    }
  }),
);

What OS/version and node/version are you seeing the problem?

OS: macOS 13.2.1
Node: 19.5.0

Additional context (optional)

No response

ghost avatar Sep 04 '23 03:09 ghost

any updates, same issue

squapllabs avatar Jan 01 '24 18:01 squapllabs

same issue

twinkle77 avatar Jul 17 '24 15:07 twinkle77