socket-function 1.2.5 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -348,8 +348,19 @@ export async function startSocketServer(
348
348
  });
349
349
  }
350
350
 
351
- let bound = await tryListen(port);
352
- if (!bound && config.useAvailablePortIfPortInUse) {
351
+ let bound = false;
352
+ // Honor an explicitly requested port first. A falsy port (0, the default) means
353
+ // "no preference" — skip straight to the scan so we land on a consistent port
354
+ // instead of an OS-assigned random one.
355
+ if (port) {
356
+ bound = await tryListen(port);
357
+ if (!bound && !config.useAvailablePortIfPortInUse) {
358
+ throw new Error(`Port ${port} is already in use (set useAvailablePortIfPortInUse to fall back to another port)`);
359
+ }
360
+ }
361
+ // Scan upwards from PORT_SCAN_START for the first free port, so restarts land on
362
+ // predictable ports.
363
+ if (!bound) {
353
364
  for (let candidate = PORT_SCAN_START; candidate < PORT_SCAN_START + PORT_SCAN_COUNT; candidate++) {
354
365
  if (candidate === port) continue;
355
366
  if (await tryListen(candidate)) {
@@ -362,9 +373,6 @@ export async function startSocketServer(
362
373
  throw new Error(`Could not find an available port in range ${PORT_SCAN_START}-${PORT_SCAN_START + PORT_SCAN_COUNT - 1} (requested ${config.port})`);
363
374
  }
364
375
  }
365
- if (!bound) {
366
- throw new Error(`Port ${port} is already in use (set useAvailablePortIfPortInUse to fall back to another port)`);
367
- }
368
376
 
369
377
  port = (realServer.address() as net.AddressInfo).port;
370
378
 
@@ -386,7 +394,9 @@ export async function startSocketServer(
386
394
  }
387
395
 
388
396
  let nodeId = getNodeId(getCommonName(config.cert), port);
389
- console.log(green(`Started Listening on ${nodeId} (${host}) after ${formatTime(process.uptime() * 1000)}`));
397
+ console.log(green(`Started Listening on ${nodeId} (${host}) after ${formatTime(process.uptime() * 1000)}`), {
398
+ domains: Object.keys(config.SNICerts || {}),
399
+ });
390
400
 
391
401
  return nodeId;
392
402
  }