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

Default port should be used if port is empty/invalid #110

Open
cvan opened this issue Dec 3, 2015 · 6 comments
Open

Default port should be used if port is empty/invalid #110

cvan opened this issue Dec 3, 2015 · 6 comments

Comments

@cvan
Copy link
Contributor

cvan commented Dec 3, 2015

I want to allow folks to spawn budo with a custom default port (instead of 9966) like this:

PORT=3000 npm start

But this won't work:

  "start": "budo --port $PORT"

budo tries to parse the empty string with parseInt and the NaN gets passed as an (invalid) port, thereby preventing budo from starting the server.

@yoshuawuyts
Copy link
Collaborator

I'd say this works as intended; if --port is passed it's your responsibility to set it. To set a default value regardless try this:

$ if [ $PORT ]; then budo --port $PORT; else budo; fi

I'm not sure what the error looks like you're getting, if it's unclear we could perhaps improve that? Cheers!

@yoshuawuyts
Copy link
Collaborator

Also to clarify: setting variables before running the script works:

 "derp": "echo $foo"
$ foo='bar' npm run foo
bar

@mattdesl
Copy link
Owner

mattdesl commented Dec 3, 2015

Yeah typically CLIs will error out when you pass undefined stuff. I think we could add a clearer error message.

@cvan
Copy link
Contributor Author

cvan commented Dec 3, 2015

I would write the command like this, but I recently discovered Git Bash on Windows doesn't like this format:

$ if [ $PORT ]; then budo --port $PORT; else budo; fi

And it's also not kind of a pain to type in each project's npm scripts.

before

empty

--port
screenshot 2015-12-03 02 30 00

invalid (non-numeric)

--port swag
screenshot 2015-12-03 02 37 57

after

valid

--port 7000
screenshot 2015-12-03 03 18 01

empty

--port
screenshot 2015-12-03 03 17 02

environment variables

PORT='' … --port $PORT
PORT=7000 … --port $PORT
screenshot 2015-12-03 03 18 30

invalid

--port swag
screenshot 2015-12-03 03 17 29

mattdesl added a commit that referenced this issue Dec 3, 2015
use default ports if empty/invalid (fixes #110)
@mattdesl
Copy link
Owner

mattdesl commented Dec 3, 2015

Seems like a pretty legitimate use case, I've run into similar issues with Unix stuff not working in Windows. Should be merged in latest, I'll cut a new release soon.

mattdesl added a commit that referenced this issue Dec 4, 2015
@mattdesl
Copy link
Owner

Going to reopen this while we figure out another way to allow user-override port/host in a cross-platform manner.

@mattdesl mattdesl reopened this Dec 17, 2015
mattdesl added a commit that referenced this issue Jan 28, 2017
use default ports if empty/invalid (fixes #110)
mattdesl added a commit that referenced this issue Jan 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants