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

minor: default support for IPv6 (#2574) #2578

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/live-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,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: "")
* @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
Expand All @@ -170,7 +170,7 @@ function entryPoint(staticHandler, file) {
*/
LiveServer.start = function (options, callback) {
options = options || {};
var host = options.host || '0.0.0.0';
var host = options.host || '';
var port = options.port !== undefined ? options.port : 8080; // 0 means random
var root = options.root || process.cwd();
var mount = options.mount || [];
Expand Down Expand Up @@ -298,14 +298,14 @@ LiveServer.start = function (options, callback) {
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 === "" ? "localhost" : address.address;
var openHost = host === "" ? "localhost" : host;

var serveURL = protocol + '://' + serveHost + ':' + address.port;
var openURL = protocol + '://' + openHost + ':' + address.port;

var serveURLs = [serveURL];
if (LiveServer.logLevel > 2 && address.address === "0.0.0.0") {
if (LiveServer.logLevel > 2 && address.address === "") {
var ifaces = os.networkInterfaces();
serveURLs = Object.keys(ifaces)
.map(function (iface) {
Expand All @@ -314,7 +314,7 @@ LiveServer.start = function (options, callback) {
// flatten address data, use only IPv4
.reduce(function (data, addresses) {
addresses.filter(function (addr) {
return addr.family === "IPv4";
return addr.family === "IPv4" || addr.family === "IPv6";
}).forEach(function (addr) {
data.push(addr);
});
Expand Down Expand Up @@ -463,4 +463,4 @@ LiveServer.shutdown = function () {
server.close();
};

module.exports = LiveServer;
module.exports = LiveServer;
2 changes: 1 addition & 1 deletion src/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class Helper {
const file = Config.getFile;
return {
port: port,
host: '0.0.0.0',
host: '',
root: rootPath,
file: file,
open: false,
Expand Down