Merge branch 'master' of https://github.com/maptiler/tileserver-gl
This commit is contained in:
22
src/utils.js
22
src/utils.js
@@ -22,10 +22,28 @@ function tileToLat(tileY, zoom) {
|
||||
return (180.0 / Math.PI) * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
|
||||
}
|
||||
|
||||
export const getPublicUrl = (publicUrl, req) => publicUrl || `${req.protocol}://${req.headers.host}/`;
|
||||
/**
|
||||
* Generate new URL object
|
||||
* @param req
|
||||
* @params {object} req - Express request
|
||||
* @returns {URL} object
|
||||
*/
|
||||
const getUrlObject = (req) => {
|
||||
const urlObject = new URL(`${req.protocol}://${req.headers.host}/`);
|
||||
// support overriding hostname by sending X-Forwarded-Host http header
|
||||
urlObject.hostname = req.hostname;
|
||||
return urlObject;
|
||||
};
|
||||
|
||||
export const getPublicUrl = (publicUrl, req) => {
|
||||
if (publicUrl) {
|
||||
return publicUrl;
|
||||
}
|
||||
return getUrlObject(req).toString();
|
||||
};
|
||||
|
||||
export const getTileUrls = (req, domains, path, format, publicUrl, aliases) => {
|
||||
|
||||
const urlObject = getUrlObject(req);
|
||||
if (domains) {
|
||||
if (domains.constructor === String && domains.length > 0) {
|
||||
domains = domains.split(',');
|
||||
|
||||
Reference in New Issue
Block a user