-
Notifications
You must be signed in to change notification settings - Fork 21
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
change server domain to 0.0.0.0 #163
Conversation
dec7e98
to
97b1f7c
Compare
I might be wrong but this change may lead that anyone on the same local network will be able to access your port, while it was not available with localhost. As I said, I might be wrong, but it's worth trying. And if so, maybe it would be interesting to make this available via a command-line parameters (like --public or whatever) I'm reporting this because of security concern |
The default behavior is to follow an npm package called Since this tool is primarily used in local development, it's better to listen on local address by default. And can be made public by specifying Good point. |
You're right. With regards to security, using the --public parameter certainly seems more prudent. The default is still set to the localhost:port configuration, but I'll make the appropriate changes. Thank you for your advice. |
I faced that issue when implementing something like that on a tool, that's why I raised the point. Also, @xhd2015 @tiezhuli001 most people won't need the feature to listen on all network ever. So yes, it should be something to pass as argument By the way, |
Yes, thanks for the suggestions. Similar to Python's http.server and Node.js's http-server, I've added --bind and --port as options to set IP and port. The default host remains as localhost. |
Perfect, thanks |
support/netutil/netutil.go
Outdated
} | ||
if _, ok := validHosts[bindStr]; ok { | ||
host = bindStr | ||
} |
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.
So no warning, error reporting here that you will fallback to local 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.
Yes, I agree that there's no need to return an error and terminate the process here.
Regardless of the situation, we should open to the default host and port - localhost should always be accessible, right?
support/netutil/netutil.go
Outdated
} | ||
} | ||
} | ||
fmt.Printf("no network interface found") |
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.
This one may cause problem
If this method failed to find an IP, you will display an error message, but the user may have provided 0.0.0.0.
So you will use it, but an error will be displayed
It's unlikely to happen I think, but I would expect the local IPs to be tested after the valid one would be tested first
url := fmt.Sprintf("http://%s:%d", host, port) | ||
fmt.Println("Server listen at:") | ||
fmt.Printf("- Local: http://%s:%d \r\n", host, port) | ||
if host == "0.0.0.0" { |
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.
I don't think this is valid hereif someone provides a bind to his public IP you won't display it.
You will have to create a function to test if the bind is purely local I think and use icon other method, or copy paste the code here
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.
I will refer to the nodejs http-server to print the corresponding URL, like this:
if (argv.a && host !== '0.0.0.0') {
logger.info( ${protocol}${host}:${chalk.green(port.toString())});
} else {
Object.keys(ifaces).forEach(function (dev) {
ifaces[dev].forEach(function (details) {
if (details.family === 'IPv4') {
logger.info((' ' + protocol + details.address + ':' + chalk.green(port.toString())));
}
});
});
}
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.
Indeed, it only displays something if not listening on everything
Need to rebase master and squash to one commit |
504b81e
to
b2c3ae1
Compare
Yes, it has been merged into one commit, thank you. |
…fault is localhost and 7070.
return | ||
} | ||
// add default router | ||
localIPs = append(localIPs, []string{"0.0.0.0", "::"}...) |
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.
Not a real issue
But, I would have written this 😅
localIPs = append(localIPs, "0.0.0.0", "::")
url := fmt.Sprintf("http://%s:%d", host, port) | ||
fmt.Println("Server listen at:") | ||
fmt.Printf("- Local: http://%s:%d \r\n", host, port) | ||
if host == "0.0.0.0" { |
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.
Indeed, it only displays something if not listening on everything
Thanks for applying the suggestions I made |
change server domain to 0.0.0.0. allow remote ssh connections to access the http address via the ip:port format.
when the host is set to 0.0.0.0 in net.Listen(), it supports both IPv4 and IPv6. Refer to: golang/go#22811