Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Show LAN IP address instead of simply `localhost`.

Use os.networkInterfaces() to get an external IP.

Also display the localhost address in case the LAN IP
is not routable when visiting from localhost.
  • Loading branch information...
commit 56dc1a80c9d28169e6544d3e2dfeabb9018c3502 1 parent 5dc9136
Reid Burke reid authored
Showing with 57 additions and 5 deletions.
  1. +57 −5 lib/cli.js
62 lib/cli.js
View
@@ -1,6 +1,7 @@
"use strict";
var nopt = require("nopt");
+var os = require("os");
var readline = require("readline");
var meta = require("./package").readPackageSync();
@@ -274,10 +275,52 @@ function submitBatch(client, options, cb) {
});
}
+var getLocalIP = (function () {
+ var cachedIP;
+
+ function queryLocalIP() {
+ var localIP,
+ addresses,
+ interfaces = os.networkInterfaces(),
+ interfaceNames = Object.keys(interfaces);
+
+ function internalOnly(address) {
+ return !address.internal;
+ }
+
+ function tryAddresses(address) {
+ // Prefer IPv4 addresses.
+ if (!localIP || address.family === "IPv4") {
+ localIP = address.address;
+ }
+ }
+
+ do {
+ interfaces[interfaceNames.pop()]
+ .filter(internalOnly)
+ .forEach(tryAddresses);
+ } while (interfaceNames.length && !localIP);
+
+ if (!localIP) {
+ localIP = "localhost";
+ }
+
+ return localIP;
+ }
+
+ return function () {
+ if (!cachedIP) {
+ cachedIP = queryLocalIP();
+ }
+ return cachedIP;
+ };
+}());
+
function runBatch(options) {
var files = options.argv.remain,
port = options.port || 9000,
url = options.hub,
+ externalUrl = url,
query = options.query,
debug = options.debug,
batchOptions = {
@@ -308,7 +351,10 @@ function runBatch(options) {
} else {
rl = readline.createInterface(process.stdin, process.stderr);
- error("Waiting for agents to connect at " + url + ".");
+ error("Waiting for agents to connect at " + externalUrl);
+ if (externalUrl !== url) {
+ error("...also available locally at " + url);
+ }
rl.question("When ready, press Enter to begin testing.\n", function () {
rl.close();
@@ -329,8 +375,10 @@ function runBatch(options) {
function createHub() {
url = "http://localhost:" + port;
+ externalUrl = "http://" + getLocalIP() + ":" + port;
- error("Creating a Hub at " + url);
+ error("Creating a Hub. Open `yeti --server` in another " +
+ "Terminal to reuse browsers for future batches.");
var client,
hub = new Hub({
@@ -349,6 +397,7 @@ function runBatch(options) {
if (err) {
throw err;
} else {
+ error(""); // Newline.
prepareTests(client);
}
});
@@ -359,12 +408,11 @@ function runBatch(options) {
client.connect(function (err) {
if (err) {
if (options.hub) {
- error("Unable to connect to Hub at", url,
+ error("Unable to connect to Hub at", externalUrl,
"with", err.stack);
}
createHub();
} else {
- error("Connected to " + url);
prepareTests(client);
}
});
@@ -372,6 +420,7 @@ function runBatch(options) {
if (!url) {
url = "http://localhost:9000";
+ externalUrl = "http://" + getLocalIP() + ":9000";
}
connectToURL(url);
@@ -379,6 +428,7 @@ function runBatch(options) {
function startServer(options) {
var port = options.port || 9000,
+ ipAddress = "127.0.0.1",
hub = new Hub({
loglevel: options.loglevel
});
@@ -392,7 +442,9 @@ function startServer(options) {
});
hub.listen(port, function () {
- error("Yeti Hub listening on port %s.", port);
+ error("Yeti Hub started. LAN: http://%s:%s\n" +
+ " Local: http://localhost:%s",
+ getLocalIP(), port, port);
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.