http-party / node-http-proxy

A full-featured http proxy for node.js
https://github.com/http-party/node-http-proxy
Other
13.88k stars 1.97k forks source link

Question: Is it possible to start proxy on a random port - how does one retrieve the port? #1675

Open Nick-Minutello opened 1 month ago

Nick-Minutello commented 1 month ago

We want to run http-proxy in our automated tests (to simulate the behaviour of our sso reverse proxy). In some cases, we may want to start a number of proxies.

In automated tests, we like to start servers on random free ports, so as to avoid any port clashes.

Of course I could call proxy.listen(0) - but it isn't clear how I can get the resultant port.

Thanks in advance

Nick-Minutello commented 1 month ago

It is possible, reaching into the internals ....

proxy._server.address().port
timtucker-dte commented 1 month ago

Why not pass in a list of potential ports into your testing scripts as input?