-
Notifications
You must be signed in to change notification settings - Fork 132
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
Allow markbind serve
to specify custom host #2382
#2395
Changes from 4 commits
71f7719
4b18adf
ed888f8
8f28bb4
d2a1d04
401bc37
813a0e2
43cd61f
fa78840
30f60a9
b602481
1cedfbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -141,7 +141,7 @@ function entryPoint(staticHandler, file) { | |||||
|
||||||
/** | ||||||
* Start a live server with parameters given as an object | ||||||
* @param host {string} Address to bind to (default: 0.0.0.0) | ||||||
* @param host {string} Address to bind to (default: 127.0.0.1) | ||||||
* @param port {number} Port number (default: 8080) | ||||||
* @param root {string} Path to root directory (default: cwd) | ||||||
* @param watch {array} Paths to exclusively watch for changes | ||||||
|
@@ -158,7 +158,7 @@ function entryPoint(staticHandler, file) { | |||||
*/ | ||||||
LiveServer.start = function(options) { | ||||||
options = options || {}; | ||||||
var host = options.host || '0.0.0.0'; | ||||||
var host = options.host !== undefined ? options.host : '127.0.0.1'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
var port = options.port !== undefined ? options.port : 8080; // 0 means random | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion, I wasn't aware of the difference between |
||||||
var root = options.root || process.cwd(); | ||||||
var mount = options.mount || []; | ||||||
|
@@ -281,7 +281,13 @@ LiveServer.start = function(options) { | |||||
setTimeout(function() { | ||||||
server.listen(0, host); | ||||||
}, 1000); | ||||||
} else { | ||||||
} else if (e.code === 'EADDRNOTAVAIL') { | ||||||
console.log('%s is not available. Trying another address'.yellow, host); | ||||||
setTimeout(function() { | ||||||
server.listen(port, '127.0.0.1'); | ||||||
}, 1000); | ||||||
} | ||||||
else { | ||||||
console.error(e.toString().red); | ||||||
LiveServer.shutdown(); | ||||||
} | ||||||
|
@@ -292,8 +298,8 @@ LiveServer.start = function(options) { | |||||
LiveServer.server = server; | ||||||
|
||||||
var address = server.address(); | ||||||
var serveHost = address.address === "0.0.0.0" ? "127.0.0.1" : address.address; | ||||||
var openHost = host === "0.0.0.0" ? "127.0.0.1" : host; | ||||||
var serveHost = address.address; | ||||||
var openHost = host; | ||||||
|
||||||
var serveURL = protocol + '://' + serveHost + ':' + address.port; | ||||||
var openURL = protocol + '://' + openHost + ':' + 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.
What do you think about adding some validation to the user input host address?
I believe that this could be better for UX as
Error: getaddrinfo ENOTFOUND 127.0.300.1
I was thinking some sort of simple validation like checking if the input is an actual IP address and if any number in the address exceeds 255 could improve the user experience
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.
Hi, good idea! I was thinking if we want to do this validation, we can actually just do the validations (including check if port is unavailable, check if host is being used etc) all at once before building the pages. Currently, all these validations are done after building the pages.
Since this PR is focusing on adding another small feature, I suggest we create a separate issue and pull request to specifically address this validation issue. What do you think?
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.
Yep I think a separate issue is fine as well! I believe there is some level of error handling for when the host is being used. From my experience if I specified a used host, the nearest unused hostname will be used, which allows the user to still serve the site. I think we can discuss about what needs to be validated once the issue is opened!