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.
*/
var plugin = module.exports = main;
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) {
errorLogger = imports["error.logger"];
register(null, {
urls: plugin
});
if (req.host)
return req.host;
if (req.url)
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} targetBaseUrlPattern The target URL pattern, e.g. https://$DOMAIN
*/
plugin.getBaseUrl = function(req, sourceBaseUrlPattern, targetBaseUrlPattern) {
var sourceHost = req.headers && req.headers.host
|| req.host
|| req.url && req.url.replace(/^https?:\/\/([^/]*).*/, "$1")
|| req;
function getBaseUrl(req, sourceBaseUrlPattern, targetBaseUrlPattern) {
var sourceHost = getHost(req);
if (typeof sourceHost !== "string")
throw new Error("Not a valid request object: " + req);
if (!sourceBaseUrlPattern)
throw new Error("getBaseUrl() requires at least two arguments");
@ -46,24 +44,29 @@ plugin.getBaseUrl = function(req, sourceBaseUrlPattern, targetBaseUrlPattern) {
.replace("$DOMAIN", "([^/]+)");
var hostMatch = sourceHost.match(sourceHostMatcher);
var targetHost;
if (hostMatch) {
targetHost = hostMatch[1];
}
else {
errorLogger.log(new Error("Could not construct URL: request host "
+ sourceHost + " should match " + sourceBaseUrlPattern));
console.error(new Error("Could not construct URL: request host " + sourceHost + " should match " + sourceBaseUrlPattern));
targetHost = "c9.io";
}
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)./))
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)
.replace(/\/$/, "");
};
}
plugin.replaceDomains = function(settings, domains) {
function replaceDomains(settings, domains) {
domains = Array.isArray(domains) ? domains : domains.split(",");
var primaryDomain = domains[0];
settings.domains = domains;
@ -85,14 +88,13 @@ plugin.replaceDomains = function(settings, domains) {
});
}
}
};
}
function replaceDomain(url, domain) {
return url.replace("$DOMAIN", domain);
}
function mockErrorLogger() {}
mockErrorLogger.log = function(err) {
console.error(err.stack);
};
plugin.mockErrorLogger = mockErrorLogger;
module.exports = {
replaceDomains: replaceDomains,
getBaseUrl: getBaseUrl,
};

Wyświetl plik

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