Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Start server on the next unoccupied port #14

Merged
merged 7 commits into from
Jun 2, 2020

Conversation

antonkomarev
Copy link
Collaborator

This feature is very useful when you are starting multiple servers. If your port is occupied - it will try to start it on the next free port.

@mpyw what do you think?

If you don't like to have this feature enabled by default - we could add option -f to enable this feature, like:

hyper-run -s localhost:4000 -f -c ~/cert.pem -t ./public

Screenshot from 2020-06-02 03-05-08

Copy link
Owner

@mpyw mpyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice feature!

@antonkomarev
Copy link
Collaborator Author

You want it to work all the time or only with -f option?

Copy link
Owner

@mpyw mpyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, it would be better that randomly allocating ports only when the port number is omitted.

  • no specification -> localhost:<random unoccupied port>
  • localhost -> localhost:<random unoccupied port>
  • localhost:8000 -> localhost:8000 or fail

@mpyw
Copy link
Owner

mpyw commented Jun 2, 2020

"random" is not really random, it's like finding the next available port number from well known port numbers such as 8000 for local servers.

@antonkomarev
Copy link
Collaborator Author

antonkomarev commented Jun 2, 2020

Good idea.

I propose to use these common specification:

Scheme Default Range
HTTP 8000 8000-8099
HTTPS 44300 44300-44399
hyper-run -S localhost -s localhost -c ~/cert.pem -t ./public

This command will run HTTP proxy on 8000 port and HTTPS proxy on 44300 port by default. If any of them occupied - the port number will be increased within the range.

@antonkomarev antonkomarev changed the title Start server on the next free unoccupied port Start server on the next unoccupied port Jun 2, 2020
@antonkomarev antonkomarev force-pushed the try-to-start-on-next-free-port branch from c194acf to ec93011 Compare June 2, 2020 17:30
@antonkomarev
Copy link
Collaborator Author

antonkomarev commented Jun 2, 2020

@mpyw I've finished this feature. Changed default ports in documentation and tests to 8000 and 43300. It's not a breaking change because people always were needed to start server with port.

README is more user friendly now. We are showing how to quick start server at the first place, and only then showing full command reference 😉

@antonkomarev antonkomarev requested a review from mpyw June 2, 2020 17:43
Copy link
Owner

@mpyw mpyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@antonkomarev antonkomarev merged commit 14a24b6 into mpyw:master Jun 2, 2020
@antonkomarev antonkomarev deleted the try-to-start-on-next-free-port branch June 2, 2020 21:11
@antonkomarev
Copy link
Collaborator Author

Released as v3.1.0

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

Successfully merging this pull request may close these issues.

2 participants