Support for handling relative subdomain patterns

This commit is contained in:
Petr Sloup 2017-03-14 15:50:14 +01:00
parent ca7a6ac515
commit b93bc5fadc

View File

@ -13,6 +13,23 @@ module.exports.getTileUrls = function(req, domains, path, format, aliases) {
if (domains.constructor === String && domains.length > 0) {
domains = domains.split(',');
}
var host = req.headers.host;
var hostParts = host.split('.');
var relativeSubdomainsUsable = hostParts.length > 1 &&
!/^([0-9]{1,3}\.){3}[0-9]{1,3}(\:[0-9]+)?$/.test(host);
var newDomains = [];
domains.forEach(function(domain) {
if (domain.indexOf('*') !== -1) {
if (relativeSubdomainsUsable) {
var newParts = hostParts.slice(1);
newParts.unshift(domain.replace('*', hostParts[0]));
newDomains.push(newParts.join('.'));
}
} else {
newDomains.push(domain);
}
});
domains = newDomains;
}
if (!domains || domains.length == 0) {
domains = [req.headers.host];