chimurai / http-proxy-middleware

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

Cannot override options in the `onProxyReq` method. #938

Open ghost opened 1 year ago

ghost commented 1 year ago

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

squapllabs commented 9 months ago

any updates, same issue

twinkle77 commented 2 months ago

same issue