TooTallNate / proxy-agents

Node.js HTTP Proxy Agents Monorepo
https://proxy-agents.n8.io
871 stars 229 forks source link

Enable localAddress #306

Open lukekarrys opened 2 months ago

lukekarrys commented 2 months ago
changeset-bot[bot] commented 2 months ago

🦋 Changeset detected

Latest commit: 8c4833d9d641cea233b51100c8ce1238f21271dd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ----- | ----- | | proxy | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
proxy-agents ✅ Ready (Inspect) Visit Preview Mar 31, 2024 8:01pm
erickythierry commented 2 months ago

Sorry if this is the wrong place to ask this, but I'm interested in the functionality of this PR.

I managed to define the outgoing interface for requests via CLI, but I wanted to do this via code.

Could you tell me how to do this?

lukekarrys commented 2 months ago

You can set localAddress on the server returned from createProxy:


import * as http from 'http';
import { createProxy } from 'proxy';

const server = createProxy(http.createServer());
server.localAddress = LOCALADDRESS;
server.listen(3128, () => {
  var port = server.address().port;
  console.log('HTTP(s) proxy server listening on port %d', port);
});
erickythierry commented 2 months ago

You can set localAddress on the server returned from createProxy:


import * as http from 'http';
import { createProxy } from 'proxy';

const server = createProxy(http.createServer());
server.localAddress = LOCALADDRESS;
server.listen(3128, () => {
  var port = server.address().port;
  console.log('HTTP(s) proxy server listening on port %d', port);
});

Thank you very much, I was looking for this