Skip to content

We should use a more rigorous logic to resolve the port of the dev server and the ‘printServerUrls’ function #7271

@libmw

Description

@libmw

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

image

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:
    image

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

  1. 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.

  2. 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.

  3. For other host I only chek the specific option host and user can only visit thier server by it.

  4. For each of the conflict port, I'll show whitch host it used by.

image

For printServerUrls I use these logic

For ipv6 networkInterface address:

  1. 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/
  2. Otherwise this address will not be displayed

For ipv4 networkInterface address:

  1. 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/
  2. 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/
  3. Otherwise this address will not be displayed

Alternative

No response

Additional context

I am working on a PR for implementing this feature.

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions