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

Add --host option to CLI #278

Closed
wants to merge 5 commits into from
Closed

Conversation

brandon93s
Copy link
Contributor

@brandon93s brandon93s commented Dec 15, 2017

Add a new option -h --host to override the host / IP of the dev server.

Closes #276

bin/cli.js Outdated
.option(
'-p, --port <port>',
'set the port to serve on. defaults to 1234',
parseInt
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added coercion to the port. Node handles it as-is, but it was resulting in a false error message on Windows:

image

bin/cli.js Outdated
require('opn')(
`http://${command.host || 'localhost'}:${server.address().port}`
);
};
Copy link
Contributor Author

@brandon93s brandon93s Dec 15, 2017

Choose a reason for hiding this comment

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

The below fixes a bug in my original implementation. Timing wasn't an issue when using localhost but listening appears to be slower (at least on Windows) when providing a host. This results in an attempted server.address().port call before listening. Simply defer if not listening yet.

Choose a reason for hiding this comment

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

You are setting the default host here, but not the default port ...

src/Bundler.js Outdated
return await Server.serve(this, port);
async serve(port = 1234, host) {
await this.bundle();
return await Server.serve(this, port, host);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was resulting in output like this:

image

Instead of like this:

image

Seems the persistent server logging should come at the end, and not be shown until everything is ready.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Caused by #164, build output was on a single line prior to that. The build time will remain the same with this change, but there could be a minor delay added between end of build and dev server availability due to the blocking. Not a big deal IMO, it should be on the magnitude of milliseconds.

Alternatives:

  • Revert this, leave the broken up logging
  • Refactor logging of server messages until build is finished

Choose a reason for hiding this comment

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

... whereas here you are setting the default port but not the default host. Can't the defaults be in the same place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rondonjon - good call! Updated to handle defaults with commander. This also gives us nicer help commands.

'set the port to serve on. defaults to 1234',
parseInt
'set the port to serve on',
x => parseInt(x, 10),
Copy link
Contributor Author

@brandon93s brandon93s Dec 20, 2017

Choose a reason for hiding this comment

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

I've seen this fail without the radix:

image

Adding for safety. Fixes the issue on my end.

@devongovett
Copy link
Member

hmm, not sure I understand the usecase here... why is this needed? doesn't the default (i.e. no host passed to the server) listen on all interfaces already?

@brandon93s
Copy link
Contributor Author

Good question. I (incorrectly) thought the default was 127.0.0.1 and not 0.0.0.0. The orignal ask (#276) was in relation to cloud9, but after reviewing their docs they're asking users to bind to 0.0.0.0 anyhow. With that in mind, it should be working as expected without these changes. In fact, these changes make the behavior more restrictive by default.

@superhawk610
Copy link

@devongovett @brandon93s the dev server itself works fine in its current form, but hot reloading does not work when viewing from hosts other than localhost (i.e. - when developing on a remote machine), as the WebSocket is hardcoded to look for localhost - see comment by @Fluidbyte on #276.

@jarlef
Copy link

jarlef commented May 29, 2018

I'm currently working on a project that needs this feature. We have a lot of sites running on subdomains including our local development sites. Cookies are often attached to the top domain (*.foo.com) and also CORS is also enabled for subdomains in the dev environment. We are basically running our local dev sites under a subdomain e.g local.foo.com etc (these domains point to 127.0.0.1 in the host file). So being able to set `-h local.foo.com -open' would be great to avoid manually changing the hostname in the address bar.

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

Successfully merging this pull request may close these issues.

5 participants