kopia lustrzana https://github.com/c9/core
Extend urls.js
rodzic
d19366c653
commit
23f3e6e809
|
@ -27,7 +27,7 @@ function main(options, imports, register) {
|
||||||
*
|
*
|
||||||
* @param req The current request object or URL
|
* @param req The current request object or URL
|
||||||
* @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) {
|
plugin.getBaseUrl = function(req, sourceBaseUrlPattern, targetBaseUrlPattern) {
|
||||||
var sourceHost = req.host || req;
|
var sourceHost = req.host || req;
|
||||||
|
@ -39,10 +39,10 @@ plugin.getBaseUrl = function(req, sourceBaseUrlPattern, targetBaseUrlPattern) {
|
||||||
if (!hostMatch) {
|
if (!hostMatch) {
|
||||||
errorLogger.log(new Error("Could not construct URL: request host "
|
errorLogger.log(new Error("Could not construct URL: request host "
|
||||||
+ sourceHost + " should match " + sourceBaseUrlPattern));
|
+ 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) {
|
plugin.replaceDomains = function(settings, domains) {
|
||||||
|
|
|
@ -120,4 +120,10 @@ describe("urls", function() {
|
||||||
var baseUrl = urls.getBaseUrl(input, "https://preview.$DOMAIN", "https://ide.$DOMAIN");
|
var baseUrl = urls.getBaseUrl(input, "https://preview.$DOMAIN", "https://ide.$DOMAIN");
|
||||||
assert.equal(baseUrl, "https://ide.newclient-lennartcl.c9.io");
|
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