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

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

Open Nick-Minutello opened this issue 1 year ago • 2 comments
trafficstars

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 avatar Jul 29 '24 10:07 Nick-Minutello

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

proxy._server.address().port

Nick-Minutello avatar Jul 30 '24 07:07 Nick-Minutello

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

timtucker-dte avatar Aug 04 '24 15:08 timtucker-dte