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

adding hostname argument to CLI #1017

Merged
merged 6 commits into from
Feb 12, 2017
Merged

Conversation

jessehattabaugh
Copy link
Contributor

No description provided.

bin/next-start Outdated
@@ -10,11 +10,13 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
hn: 'hostname',
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 -H or -a (address) is better.

Copy link
Member

Choose a reason for hiding this comment

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

We use -H for micro lets use that to keep it consistent.

@jessehattabaugh
Copy link
Contributor Author

jessehattabaugh commented Feb 7, 2017 via email

Copy link
Contributor Author

@jessehattabaugh jessehattabaugh left a comment

Choose a reason for hiding this comment

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

I made the change to the arg alias as requested. It's now -H instead of -hn

bin/next-start Outdated
p: 'port'
},
boolean: ['h'],
default: {
p: 3000
p: 3000,
hostname: 'localhost'
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'll be safe to not have default value for hostname.

Copy link
Contributor

@arunoda arunoda Feb 8, 2017

Choose a reason for hiding this comment

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

Yeah! I think with this it only listen on localhost not with others like 127.0.0.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.

If there's no default then the second argument to listen() will be undefined. I'm not sure what that would do.

Copy link
Member

@timneutkens timneutkens Feb 8, 2017

Choose a reason for hiding this comment

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

taken from https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback:

If the hostname is omitted, the server will accept connections on any IPv6 address (::) when IPv6 is available, or any IPv4 address (0.0.0.0) otherwise.

@nkzawa is right 😄

Copy link
Contributor Author

@jessehattabaugh jessehattabaugh Feb 8, 2017

Choose a reason for hiding this comment

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

"omitted", but what if undefined or null is passed? There's one way to find out I guess

Copy link
Member

Choose a reason for hiding this comment

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

@jessehattabaugh great though actually. Only now I'm remembering that when you pass -H without a hostname it will actually turn into true

server/index.js Outdated
await this.prepare()
this.http = http.createServer(this.getRequestHandler())
await new Promise((resolve, reject) => {
// This code catches EADDRINUSE error if the port is already in use
this.http.on('error', reject)
this.http.on('listening', () => resolve())
this.http.listen(port)
if (hostname) this.http.listen(port, hostname)
Copy link
Contributor Author

@jessehattabaugh jessehattabaugh Feb 8, 2017

Choose a reason for hiding this comment

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

I decided to be careful and only call listen() with a hostname arg if something truthy is passed to start

Copy link
Member

Choose a reason for hiding this comment

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

please make this a if/else with { and }, standardjs should have caught this 🤔

Copy link
Member

Choose a reason for hiding this comment

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

taken from my other comment:

@jessehattabaugh great though actually. Only now I'm remembering that when you pass -H without a hostname it will actually turn into true

If you check for hostname it will evaluate to true when passing -H 😅 It think it's best to check if it is a valid number or something like that 🤔

cc @nkzawa

await this.prepare()
this.http = http.createServer(this.getRequestHandler())
await new Promise((resolve, reject) => {
// This code catches EADDRINUSE error if the port is already in use
this.http.on('error', reject)
this.http.on('listening', () => resolve())
this.http.listen(port)
if (hostname && typeof hostname !== 'boolean') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@timneutkens good catch about empty -H evaluating true

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 we can use the string option of minimist.

Copy link
Member

Choose a reason for hiding this comment

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

True, merging this in, will fix after merging.

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

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

I'll fix @nkzawa's note on minimist's string option.

@timneutkens timneutkens merged commit c4a22ab into vercel:master Feb 12, 2017
@schoenwaldnils
Copy link
Contributor

Would it make sense to have those things (port, hostname) editable in the next.config.js?

@timneutkens
Copy link
Member

timneutkens commented Dec 17, 2018

No, as they're runtime values and are only applicable when using next / next start. See #5846

@schoenwaldnils
Copy link
Contributor

Hm, ok, that sounds plausible.
What about the CLI option to point at another config file in which all CLI options could be defined?
Like next dev --config config.js?

@timneutkens
Copy link
Member

You could create a shell script with predefined options.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants