Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dev-server): Add Option to Disable Automatic Port Reassignment in Dev Server #6044

Open
3 tasks done
lukep-coxauto opened this issue Nov 10, 2024 · 1 comment
Open
3 tasks done

Comments

@lukep-coxauto
Copy link

lukep-coxauto commented Nov 10, 2024

Prerequisites

Describe the Feature Request

Add a CLI parameter that will disable the automatic port incrementing behavior when the open port is currently in use. For example, if you ask to bind to port 3003, but ports 3003-3009 are in use, the devServer will currently bind to port 3010.

Describe the Use Case

When working on micro frontends locally, multiple Stencil dev servers may be run in parallel, and an outside process is responsible for coordinating the rendering of the multiple frontends into a single application. In situations like this, it's easy to lose a tab running a dev server and attempt to start up another instance of a micro frontend that's already running a dev server instance. There are many instances where multiple services may need to be run locally and orchestrated together into a larger app, and the common denominator across tech stacks is the ports that the services are bound to. When applications are allowed to roam across ports, it makes it difficult or impossible to enforce that the expected service is running at the port indicated, so the lack of this feature causes conflicts with other technologies as well, since the Stencil dev server can't be a "good citizen" of local port allocation because it can claim ports that may not belong to it.

Describe Preferred Solution

Add a mechanism from the CLI allowing the customization of this behavior. The Vite behavior seems to me like the preferred solution, since it is incrementally enhancing behavior without any backwards incompatibility. Introduce the strictPort option, and default it to false, which will result in identical behavior to Vite and to current Stencil Dev Server. Then implement strictPort as true, which will enable this new behavior.

Describe Alternatives

I am currently using mechanisms outside of the devServer to force the startup scripts to abort if the preferred ports are in use, but this is not required in either Vite or Webpack projects, only for Stencil, it requires extra code, and it is difficult to make it function correctly in a cross-platform way as it depends on additional tooling. Ideally Stencil devServer would support forcing a standard port, as several other common dev servers currently allow.

Related Code

The config for the CLI would need an additional parameter introduced and documented, perhaps called strictPort and of boolean type.

Additional Information

Vite's dev server as an example has both the port and strictPort CLI properties. port is used to bind to a specific port, identically to Stencil's port property. If strictPort is false, the behavior is the same as the Stencil dev server, where if the preferred port is taken, the next incremented port number that is free is used. If strictPort is true, then the dev server fails to start up if the port binding is not possible on the specified port.

Webpack solves this by either specifying port: auto which has the roaming port behavior, or port: {number} which requires the specified port to be enabled. See the devServer documentation for more details.

@ionitron-bot ionitron-bot bot added the triage label Nov 10, 2024
@christian-bromann
Copy link
Member

The described preferred solution seems reasonable to me. Any contributions would be much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants