(startPort, exclude = new Set())
| 27 | } |
| 28 | |
| 29 | async function pickPort(startPort, exclude = new Set()) { |
| 30 | for (let port = startPort; port < startPort + MAX_PROBE; port += 1) { |
| 31 | if (exclude.has(port)) continue; |
| 32 | // eslint-disable-next-line no-await-in-loop |
| 33 | if (await isFree(port)) return port; |
| 34 | } |
| 35 | throw new Error( |
| 36 | `no free port in [${startPort}, ${startPort + MAX_PROBE}); something is hogging the range`, |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | const requestedApi = Number(process.env.PORT) || DEFAULT_API_PORT; |
| 41 | const apiPort = await pickPort(requestedApi); |