Skip to content

Commit

Permalink
Revert default bind IP to 0.0.0.0.
Browse files Browse the repository at this point in the history
We still use localhost as DDP_DEFAULT_CONNECTION_URL for mobile builds
if another host isn't provided; we just don't want localhost to
overwrite an unspecified host for the proxy to bind to.

Fixes #2596.
  • Loading branch information
Emily Stark committed Sep 18, 2014
1 parent e1691e0 commit 792edd2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
44 changes: 31 additions & 13 deletions tools/commands.js
Expand Up @@ -29,6 +29,11 @@ var execFileSync = require('./utils.js').execFileSync;
// by 'meteor deploy'.
var DEPLOY_ARCH = 'os.linux.x86_64';

// The default host to use when building apps. (Specifically, for mobile
// builds, we need a host to use for DDP_DEFAULT_CONNECTION_URL if the
// user doesn't specify one with -p or --mobile-port).
var DEFAULT_BUILD_HOST = "localhost";

// Given a site name passed on the command line (eg, 'mysite'), return
// a fully-qualified hostname ('mysite.meteor.com').
//
Expand Down Expand Up @@ -64,7 +69,7 @@ var parseHostPort = function (str) {
"port is a number. Try 'meteor help run' for help.\n");
}

var host = portMatch[1] || 'localhost';
var host = portMatch[1];
var port = parseInt(portMatch[2]);

return {
Expand Down Expand Up @@ -213,18 +218,19 @@ main.registerCommand({
return 1;
}

parsedMobileHostPort.host = parsedMobileHostPort.host || DEFAULT_BUILD_HOST;

options.httpProxyPort = options['http-proxy-port'];

// If we are targeting the remote devices
if (_.intersection(options.args, ['ios-device', 'android-device']).length) {
cordova.verboseLog('A run on a device requested');
// ... and if you didn't specify your ip address as host, print a warning
if (parsedHostPort.host === 'localhost')
if (parsedMobileHostPort.host === DEFAULT_BUILD_HOST)
process.stderr.write(
"WARN: You are testing your app on a remote device but your host option\n" +
"WARN: is set to 'localhost'. Perhaps you want to change it to your local\n" +
"WARN: network's IP address with the -p option?\n");
"WARN: network's IP address with the -p or --mobile-port option?\n");
}

// Always bundle for the browser by default.
Expand Down Expand Up @@ -555,7 +561,7 @@ var buildCommands = {
debug: { type: Boolean },
directory: { type: Boolean },
architecture: { type: String },
port: { type: String, short: "p", default: "localhost:3000" },
port: { type: String, short: "p", default: DEFAULT_BUILD_HOST + ":3000" },
settings: { type: String },
verbose: { type: Boolean, short: "v" },
// Undocumented
Expand Down Expand Up @@ -595,11 +601,6 @@ main.registerCommand(_.extend({ name: 'build' }, buildCommands),
var appName = path.basename(options.appDir);

if (! _.isEmpty(mobilePlatforms)) {
if (options.port === buildCommands.options.port.default) {
process.stdout.write("WARNING: Building your app with host: localhost.\n" +
"Pass a -p argument to specify a host URL.\n");
}
var cordovaSettings = {};

try {
var parsedHostPort = parseHostPort(options.port);
Expand All @@ -608,8 +609,21 @@ main.registerCommand(_.extend({ name: 'build' }, buildCommands),
return 1;
}

// For Cordova builds, if a host isn't specified, use localhost, but
// warn about it.
var cordovaBuildHost = parsedHostPort.host || DEFAULT_BUILD_HOST;
if (cordovaBuildHost === DEFAULT_BUILD_HOST) {
process.stdout.write("WARNING: Building your app with host: localhost.\n" +
"Pass a -p argument to specify a host URL.\n");
}
var cordovaSettings = {};

cordova.buildPlatforms(localPath, mobilePlatforms,
_.extend({}, options, parsedHostPort, { appName: appName }));
_.extend({}, options, {
host: cordovaBuildHost,
port: parsedHostPort.port,
appName: appName
}));
}

var buildDir = path.join(localPath, 'build_tar');
Expand Down Expand Up @@ -1184,6 +1198,7 @@ main.registerCommand({
_.extend(options, parsedHostPort);

var testPackages = null;
var localPackages = null;
try {
var packages = getPackagesForTest(options.args);
testPackages = packages.testPackages;
Expand Down Expand Up @@ -1230,7 +1245,7 @@ main.registerCommand({
// For this release; we won't force-enable the httpProxy
if (false) { //!options.httpProxyPort) {
console.log('Forcing http proxy on port 3002 for mobile');
options.httpProxyPort = '3002'
options.httpProxyPort = '3002';
}

var localPath = path.join(testRunnerAppDir, '.meteor', 'local');
Expand All @@ -1246,9 +1261,12 @@ main.registerCommand({
cordova.buildPlatforms(localPath, mobilePlatforms,
_.extend({}, options, {
appName: path.basename(testRunnerAppDir),
debug: ! options.production
debug: ! options.production,
// Default to localhost for mobile builds.
host: parsedHostPort.host || DEFAULT_BUILD_HOST
}));
runners = runners.concat(cordova.buildPlatformRunners(localPath, mobilePlatforms, options));
runners = runners.concat(cordova.buildPlatformRunners(
localPath, mobilePlatforms, options));
} catch (err) {
process.stderr.write(err.message + '\n');
return 1;
Expand Down
2 changes: 1 addition & 1 deletion tools/run-all.js
Expand Up @@ -51,7 +51,7 @@ var Runner = function (appDir, options) {
if (options.httpProxyPort) {
self.httpProxy = new HttpProxy({
listenPort: options.httpProxyPort
})
});
}

self.mongoRunner = null;
Expand Down

0 comments on commit 792edd2

Please sign in to comment.