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: checking if port is used and adding new flag to change the default port #15

Merged
merged 2 commits into from
May 31, 2018

Conversation

Dohxis
Copy link
Contributor

@Dohxis Dohxis commented May 29, 2018

Feature

Added --port and -p flags so it would be easier to change the default port. Also added checking if a port is already used by a different application and in that case server will try to choose an open port.

ports

terminal.print "#{COG} Would you like to to use port #{new_port} instead? (Y/n)\n"

use_new_port = gets
if use_new_port === "y" || use_new_port === "Y"
Copy link
Contributor

@veelenga veelenga May 29, 2018

Choose a reason for hiding this comment

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

Maybe, a bit more uniform:

use_new_port.downcase == "y"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks!

server =
HTTP::Server.new(config.host_binding, port, config.handlers)
terminal.print "#{COG} Development server started on http://#{config.host_binding}:#{port}/\n"
else
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should fail in this case. Having blocking terminal IO on a webserver isn't good practice since it looks like the server is running while in reality it's waiting for user input.
So we could at least check if the terminal is a tty first and fail otherwise. Something like STDIN.tty? should do the trick.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tested it so not sure what you mean by saying it should fail. But if it something important I am happy to change it just point me to the direction how it should be implemented.

Copy link
Member

Choose a reason for hiding this comment

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

Yes @manveru is right, someone might use mint start as production server for whatever reason and suppressing the output like mint start > /dev/null would cause it to behave like it's running while in reality it's waiting for user input.

This should be the branch of elseif STDIN.tty? and then the else branch would just exit with a nice message and a code of 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I understand what are you talking about, going to add this today.

long: port,
short: p,
default: 3000_i32,
required: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Also would be awesome if it respected the PORT and HOST environment variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to add this soon.

@manveru
Copy link
Contributor

manveru commented May 29, 2018 via email

else
terminal.print "#{COG} Exiting...\n"
end
else
Copy link
Member

Choose a reason for hiding this comment

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

How failures are handled in mint is by raising an instance of error https://github.com/mint-lang/mint/tree/master/src/errors which the command handles https://github.com/mint-lang/mint/blob/master/src/commands/command.cr#L43 by printing it's message and exiting with code 1.

Would be nice to have it this way, but It can stay as is, it just needs to exit 1 instead of returning 1.

Copy link
Contributor Author

@Dohxis Dohxis left a comment

Choose a reason for hiding this comment

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

Changed everything that was requested.

@gdotdesign gdotdesign merged commit 4d4081f into mint-lang:master May 31, 2018
@Dohxis Dohxis deleted the port-checking branch May 31, 2018 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants