kopia lustrzana https://github.com/c9/core
Extend urls.js
rodzic
d19366c653
commit
23f3e6e809
|
@ -25,9 +25,9 @@ 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 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
|
||||
*/
|
||||
plugin.getBaseUrl = function(req, sourceBaseUrlPattern, targetBaseUrlPattern) {
|
||||
var sourceHost = req.host || req;
|
||||
|
@ -39,10 +39,10 @@ plugin.getBaseUrl = function(req, sourceBaseUrlPattern, targetBaseUrlPattern) {
|
|||
if (!hostMatch) {
|
||||
errorLogger.log(new Error("Could not construct URL: request host "
|
||||
+ sourceHost + " should match " + sourceBaseUrlPattern));
|
||||
return replaceDomain(targetBaseUrlPattern, "c9.io");
|
||||
return replaceDomain(targetBaseUrlPattern || sourceBaseUrlPattern, "c9.io");
|
||||
}
|
||||
|
||||
return replaceDomain(targetBaseUrlPattern, hostMatch[1]);
|
||||
return replaceDomain(targetBaseUrlPattern || sourceBaseUrlPattern, hostMatch[1]);
|
||||
};
|
||||
|
||||
plugin.replaceDomains = function(settings, domains) {
|
||||
|
|
|
@ -120,4 +120,10 @@ describe("urls", function() {
|
|||
var baseUrl = urls.getBaseUrl(input, "https://preview.$DOMAIN", "https://ide.$DOMAIN");
|
||||
assert.equal(baseUrl, "https://ide.newclient-lennartcl.c9.io");
|
||||
});
|
||||
|
||||
it("targetBaseUrlPattern is optional", function() {
|
||||
var input = "https://preview.newclient-lennartcl.c9.io";
|
||||
var baseUrl = urls.getBaseUrl(input, "https://preview.$DOMAIN");
|
||||
assert.equal(baseUrl, "https://preview.newclient-lennartcl.c9.io");
|
||||
});
|
||||
});
|
Ładowanie…
Reference in New Issue