lukejacksonn / servor

Dependency free file server for single page app development
MIT License
1.04k stars 70 forks source link

Starting two instances of Servor without port cause them having the same port #56

Open nestarz opened 4 years ago

nestarz commented 4 years ago

Using the API, I start two instances of Servor without waiting the first promise to finish, without port specified, the net library cause them to have the same port.

If I just do this it works:

const usePort = (port = 0) =>
  new Promise((ok, x) => {
    setTimeout(() => {
      const s = net.createServer();
      s.on('error', x);
      s.listen(port, () => (a = s.address()) && s.close(() => ok(a.port)));
    })
  });

They have two differents ports, (51159 and 51160 for example).

lukejacksonn commented 4 years ago

Hey 👋 thanks for the report.. just so that I am clear whats going on, you do something like this:

import servor from 'servor';

servor({ ... })
servor({ ... })

And this results in both servers running on the same port?

nestarz commented 4 years ago

Exactly !