unjs / get-port-please

🔌 Get an available open port
MIT License
255 stars 13 forks source link

feat: add `host` option #4

Closed mrazauskas closed 3 years ago

mrazauskas commented 3 years ago

At the moment getPort() always checks ports on 0.0.0.0.

Issue: if some app already listens on localhost:3000 (rather usual in dev environment), getPort(3000) will return 3000. It simply checked if 0.0.0.0:3000 is free. (Would be good to check, but it sounds similar to issue #3.)

Solution: we need a possibility to check host and port combination. In similar situation like above getPort({ host: 'localhost' }) would return 4000.

What should be the default value of the host option? Perhaps the same, which is used by listhen?

pi0 commented 3 years ago

What should be the default value of the host option? Perhaps the same, which is used by listhen?

I think we might ideally support host as array to check both 127.0.0.1 (internal) and 0.0.0.0 (external)

mrazauskas commented 3 years ago

Hosts array as default value. That’s really smart! I will try it out.