diff --git a/packages/meteor/url_server.js b/packages/meteor/url_server.js index 81b55e776f..9eee42f0c3 100644 --- a/packages/meteor/url_server.js +++ b/packages/meteor/url_server.js @@ -1,6 +1,15 @@ if (process.env.ROOT_URL && typeof __meteor_runtime_config__ === "object") { __meteor_runtime_config__.ROOT_URL = process.env.ROOT_URL; - var pathPrefix = Npm.require('url').parse(__meteor_runtime_config__.ROOT_URL).pathname; - __meteor_runtime_config__.ROOT_URL_PATH_PREFIX = pathPrefix === "/" ? "" : pathPrefix; + if (__meteor_runtime_config__.ROOT_URL) { + var parsedUrl = Npm.require('url').parse(__meteor_runtime_config__.ROOT_URL); + // Sometimes users try to pass, eg, ROOT_URL=mydomain.com. + if (!parsedUrl.host) { + throw Error("$ROOT_URL, if specified, must be an URL"); + } + var pathPrefix = parsedUrl.pathname; + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX = pathPrefix === "/" ? "" : pathPrefix; + } else { + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX = ""; + } } diff --git a/tools/main.js b/tools/main.js index 5ec8a8622b..4521e2b9f5 100644 --- a/tools/main.js +++ b/tools/main.js @@ -337,6 +337,17 @@ Fiber(function () { process.exit(1); } + // This is a bit of a hack, but: if we don't check this in the tool, then the + // first time we do a unipackage.load, it will fail due to the check in the + // meteor package, and that'll look a lot uglier. + if (process.env.ROOT_URL) { + var parsedUrl = require('url').parse(process.env.ROOT_URL); + if (!parsedUrl.host) { + process.stderr.write('$ROOT_URL, if specified, must be an URL.\n'); + process.exit(1); + } + } + // Parse the arguments. // // We must first identify which options are boolean and which take