Repository navigation
feat: auto-shift port when default is in use (Vite-style) - #14
Merged
Merged
Conversation
If the requested port is busy, probe up to 10 ports above it (net.createServer-based bind test on the same host JSS will use) and use the first free one. Print a clear "Port 5444 is in use, using 5445 instead." line if shifted. Errors with a hint to pass --port if no slot is free in the range. Mirrors Vite/Next.js dev-server behaviour. Solves the most common "jspod already running" friction without forcing the user to read an error and retry with --port. Bumps jspod to 0.0.16.
29 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
If 5444 is already taken (another jspod running, dev server collision, whatever) jspod previously crashed on JSS bind. Now jspod probes the requested port and shifts up by one — up to 10 attempts — finding the first free port and printing a clear line before the banner:
```
Port 5444 is in use, using 5445 instead.
```
Mirrors Vite / Next.js dev-server behaviour. Solves the most common "I already have jspod running" friction.
Implementation
Adds a small
findFreePort(startPort, host)helper using `net.createServer().listen(port, host)` — bind succeeds → free, EADDRINUSE → take the next one. Probes against the same host JSS will bind to so the answer reflects reality.After CLI parse, before banner display, jspod calls `await findFreePort(options.port, options.host)`. If the returned port differs from the requested one, prints the yellow warning. If no free port in the 10-port range, exits with a clear error pointing at `--port`.
Test plan
ss -tlnp)npx jspod@0.0.16while another jspod is running; confirm the shift + browser auto-opens to the right portRefs #1