From a8869d07ec4fc7771b82e83d632023a331be076a Mon Sep 17 00:00:00 2001 From: David Glasser Date: Tue, 22 Apr 2014 15:52:52 -0700 Subject: [PATCH] Provide a better error if ROOT_URL is not an URL Fixes #1404. --- packages/meteor/url_server.js | 13 +++++++++++-- tools/main.js | 11 +++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) 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