-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Clear and concise description of the problem
As a developer using Vite I want optimize the resolve logic of develop server port and the server running at... log.So that user can visit thier dev server correctlly.
I intend to submit a PR for this issue.
Vite is able to find another port when the candidate port is used by other program,but it's not rigorous sometimes.
Incorrect localhost
- For webpack if you don't explicitly set the host for dev server,it will use undefined,see https://github.com/webpack/webpack-dev-server/blob/v4.7.4/lib/Server.js#L3207,whitch cause nodejs listen on '::' (https://github.com/nodejs/node/blob/v17.7.1/lib/net.js#L1304).For vite in the same case it will listen on '127.0.0.1',and both can be successful. But then vite will tell you visit //localhost:port,whitch will parse to webpack devserver by most browser.That because localhost is parse to '::1' first.This is confusing for users,it seem vite is a liar.
Vite will show unreachable ip
- When the compute have more than one network interface,vite will show all of then,even the ip is unreachable:

Suggested solution
I don't know if the above questions are bugs or rules,but I still try to optimize them.
For port conflicts I try to optimize by
-
If option host is undefined or :: or 0.0.0.0, user mostly want to visit thier server by every address.I would check all local address to see if they are used by option port.
-
If option host is 127.0.0.1 or localhost,user mostly want to visit thier server by localhost.I would check 127.0.0.1 and ::1 and :: with option port to make sure that users can use localhost to access thier server.
-
For other host I only chek the specific option host and user can only visit thier server by it.
-
For each of the conflict port, I'll show whitch host it used by.
For printServerUrls I use these logic
For ipv6 networkInterface address:
- If the address is equal to the opiton host and the option host is not ::,this address will be used as the host name.ie: http://[::1]:3000/
- Otherwise this address will not be displayed
For ipv4 networkInterface address:
- If the address is equal to the opiton host , or opiton host is undefined or 0.0.0.0 or :: ,this address will be used as the host name..ie: http://192.0.0.1:3000/
- If the address is 127.0.0.1 and the option host is not ::1 ,this address will be displayd as the resolved host name. ie: http://localhost:3000/
- Otherwise this address will not be displayed
Alternative
No response
Additional context
I am working on a PR for implementing this feature.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

