Handle relative publicUrl value
This commit is contained in:
parent
e506014763
commit
203a0161e6
1 changed files with 10 additions and 3 deletions
13
src/utils.js
13
src/utils.js
|
|
@ -1,14 +1,19 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var path = require('path'),
|
var path = require('path'),
|
||||||
fs = require('fs');
|
fs = require('fs'),
|
||||||
|
url = require('url');
|
||||||
|
|
||||||
var clone = require('clone'),
|
var clone = require('clone'),
|
||||||
glyphCompose = require('glyph-pbf-composite');
|
glyphCompose = require('glyph-pbf-composite');
|
||||||
|
|
||||||
|
|
||||||
module.exports.getPublicUrl = function(publicUrl, req) {
|
module.exports.getPublicUrl = function(publicUrl, req) {
|
||||||
return publicUrl || (req.protocol + '://' + req.headers.host + '/')
|
if (publicUrl) {
|
||||||
|
return (new url.URL(publicUrl, req.protocol + '://' + req.headers.host)).toString()
|
||||||
|
} else {
|
||||||
|
return req.protocol + '://' + req.headers.host + '/'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getTileUrls = function(req, domains, path, format, publicUrl, aliases) {
|
module.exports.getTileUrls = function(req, domains, path, format, publicUrl, aliases) {
|
||||||
|
|
@ -54,13 +59,15 @@ module.exports.getTileUrls = function(req, domains, path, format, publicUrl, ali
|
||||||
}
|
}
|
||||||
|
|
||||||
var uris = [];
|
var uris = [];
|
||||||
|
|
||||||
if (!publicUrl) {
|
if (!publicUrl) {
|
||||||
domains.forEach(function(domain) {
|
domains.forEach(function(domain) {
|
||||||
uris.push(req.protocol + '://' + domain + '/' + path +
|
uris.push(req.protocol + '://' + domain + '/' + path +
|
||||||
'/{z}/{x}/{y}.' + format + query);
|
'/{z}/{x}/{y}.' + format + query);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
uris.push(publicUrl + path + '/{z}/{x}/{y}.' + format + query)
|
uris.push(module.exports.getPublicUrl(publicUrl, req) + path +
|
||||||
|
'/{z}/{x}/{y}.' + format + query)
|
||||||
}
|
}
|
||||||
|
|
||||||
return uris;
|
return uris;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue