This commit is contained in:
Ivan Vazhenin
2023-10-05 15:36:21 +03:00
parent d44e288a31
commit 5767fff19d

View File

@@ -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(',');