-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conversation
bin/cli.js
Outdated
.option( | ||
'-p, --port <port>', | ||
'set the port to serve on. defaults to 1234', | ||
parseInt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bin/cli.js
Outdated
require('opn')( | ||
`http://${command.host || 'localhost'}:${server.address().port}` | ||
); | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
Good question. I (incorrectly) thought the default was |
@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. |
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. |
Add a new option
-h --host
to override the host / IP of the dev server.Closes #276