restructure not to be architect plugin

pull/223/head
Matthijs van Henten 2015-10-19 22:30:12 +00:00
rodzic 699e96e85d
commit 01e56ab0af
2 zmienionych plików z 33 dodań i 29 usunięć

60
node_modules/c9/urls.js wygenerowano vendored
Wyświetl plik

@ -6,20 +6,19 @@
* @copyright 2015, Ajax.org B.V. * @copyright 2015, Ajax.org B.V.
*/ */
var plugin = module.exports = main;
var assert = require("assert"); var assert = require("assert");
plugin.consumes = ["error.logger"];
plugin.provides = ["urls"];
var errorLogger = mockErrorLogger; function getHost(req) {
if (req.headers)
return req.headers.host;
function main(options, imports, register) { if (req.host)
errorLogger = imports["error.logger"]; return req.host;
register(null, { if (req.url)
urls: plugin return req.url.replace(/^https?:\/\/([^/]*).*/, "$1");
});
return req;
} }
/** /**
@ -29,13 +28,12 @@ function main(options, imports, register) {
* @param {String} [sourceUrlPattern] The source URL pattern, e.g. https://ide.$DOMAIN * @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} targetBaseUrlPattern The target URL pattern, e.g. https://$DOMAIN
*/ */
plugin.getBaseUrl = function(req, sourceBaseUrlPattern, targetBaseUrlPattern) { function getBaseUrl(req, sourceBaseUrlPattern, targetBaseUrlPattern) {
var sourceHost = req.headers && req.headers.host var sourceHost = getHost(req);
|| req.host
|| req.url && req.url.replace(/^https?:\/\/([^/]*).*/, "$1")
|| req;
if (typeof sourceHost !== "string") if (typeof sourceHost !== "string")
throw new Error("Not a valid request object: " + req); throw new Error("Not a valid request object: " + req);
if (!sourceBaseUrlPattern) if (!sourceBaseUrlPattern)
throw new Error("getBaseUrl() requires at least two arguments"); throw new Error("getBaseUrl() requires at least two arguments");
@ -46,24 +44,29 @@ plugin.getBaseUrl = function(req, sourceBaseUrlPattern, targetBaseUrlPattern) {
.replace("$DOMAIN", "([^/]+)"); .replace("$DOMAIN", "([^/]+)");
var hostMatch = sourceHost.match(sourceHostMatcher); var hostMatch = sourceHost.match(sourceHostMatcher);
var targetHost; var targetHost;
if (hostMatch) { if (hostMatch) {
targetHost = hostMatch[1]; targetHost = hostMatch[1];
} }
else { else {
errorLogger.log(new Error("Could not construct URL: request host " console.error(new Error("Could not construct URL: request host " + sourceHost + " should match " + sourceBaseUrlPattern));
+ sourceHost + " should match " + sourceBaseUrlPattern));
targetHost = "c9.io"; targetHost = "c9.io";
} }
if (targetHost.match(/^(ide|vfs)./) && !targetBaseUrlPattern) if (targetHost.match(/^(ide|vfs)./) && !targetBaseUrlPattern)
errorLogger.log(new Error("Warning: no targetBaseUrlPattern specified, will stay at " + targetHost), { sourceBaseUrlPattern: sourceBaseUrlPattern }); console.error(new Error("Warning: no targetBaseUrlPattern specified, will stay at " + targetHost), {
sourceBaseUrlPattern: sourceBaseUrlPattern
});
if (targetHost.match(/^(ide|vfs)./)) if (targetHost.match(/^(ide|vfs)./))
console.trace("Warning: possibly incorrect baseUrl constructed, with 'ide.' in the hostname: " + targetHost); console.trace("Warning: possibly incorrect baseUrl constructed, with 'ide.' in the hostname: " + targetHost);
return replaceDomain(targetBaseUrlPattern || sourceBaseUrlPattern, targetHost) return replaceDomain(targetBaseUrlPattern || sourceBaseUrlPattern, targetHost)
.replace(/\/$/, ""); .replace(/\/$/, "");
}; }
plugin.replaceDomains = function(settings, domains) { function replaceDomains(settings, domains) {
domains = Array.isArray(domains) ? domains : domains.split(","); domains = Array.isArray(domains) ? domains : domains.split(",");
var primaryDomain = domains[0]; var primaryDomain = domains[0];
settings.domains = domains; settings.domains = domains;
@ -85,14 +88,13 @@ plugin.replaceDomains = function(settings, domains) {
}); });
} }
} }
}; }
function replaceDomain(url, domain) { function replaceDomain(url, domain) {
return url.replace("$DOMAIN", domain); return url.replace("$DOMAIN", domain);
} }
function mockErrorLogger() {} module.exports = {
mockErrorLogger.log = function(err) { replaceDomains: replaceDomains,
console.error(err.stack); getBaseUrl: getBaseUrl,
}; };
plugin.mockErrorLogger = mockErrorLogger;

Wyświetl plik

@ -108,6 +108,8 @@
"c9.ide.save": "#e00549cb0f", "c9.ide.save": "#e00549cb0f",
"c9.ide.scm": "#38d2b48b31", "c9.ide.scm": "#38d2b48b31",
"c9.ide.terminal.monitor": "#b76f1c9f24", "c9.ide.terminal.monitor": "#b76f1c9f24",
"c9.ide.test": "#d312a01ac6",
"c9.ide.test.mocha": "#79ff886c04",
"c9.ide.theme.flat": "#2de8414db7", "c9.ide.theme.flat": "#2de8414db7",
"c9.ide.threewaymerge": "#229382aa0b", "c9.ide.threewaymerge": "#229382aa0b",
"c9.ide.undo": "#b028bcb4d5", "c9.ide.undo": "#b028bcb4d5",