diff --git a/node_modules/c9/urls.js b/node_modules/c9/urls.js index 4b0c12ee..429ba8e2 100644 --- a/node_modules/c9/urls.js +++ b/node_modules/c9/urls.js @@ -26,8 +26,8 @@ function main(options, imports, register) { * Get a desired base URL, given some context. * * @param req The current request object or URL - * @param {String} sourceUrlPattern The source URL pattern, e.g. https://ide.$DOMAIN - * @param {String} [targetBaseUrlPattern] The target URL pattern, e.g. https://$DOMAIN + * @param {String} [sourceUrlPattern] The source URL pattern, e.g. https://ide.$DOMAIN + * @param {String} targetBaseUrlPattern The target URL pattern, e.g. https://$DOMAIN */ plugin.getBaseUrl = function(req, sourceBaseUrlPattern, targetBaseUrlPattern) { var sourceHost = req.headers && req.headers.host @@ -39,15 +39,20 @@ plugin.getBaseUrl = function(req, sourceBaseUrlPattern, targetBaseUrlPattern) { .replace(/\/.*/, "") .replace("$DOMAIN", "([^/]+)"); var hostMatch = sourceHost.match(sourceHostMatcher); - if (!hostMatch) { + var targetHost; + if (hostMatch) { + targetHost = hostMatch[1]; + } + else { errorLogger.log(new Error("Could not construct URL: request host " + sourceHost + " should match " + sourceBaseUrlPattern)); - return replaceDomain(targetBaseUrlPattern || sourceBaseUrlPattern, "c9.io") - .replace(/\/$/, ""); + targetHost = "c9.io"; } - return replaceDomain(targetBaseUrlPattern || sourceBaseUrlPattern, hostMatch[1]) - .replace(/\/$/, "");; + if (targetHost.match(/^(ide|vfs)./) && !targetBaseUrlPattern) + errorLogger.log(new Error("Warning: no targetBaseUrlPattern specified, will stay at " + targetHost), { sourceBaseUrlPattern: sourceBaseUrlPattern }); + return replaceDomain(targetBaseUrlPattern || sourceBaseUrlPattern, targetHost) + .replace(/\/$/, ""); }; plugin.replaceDomains = function(settings, domains) {