fix: improve getUrlObject

Signed-off-by: Manuel Roth <manuelroth@hotmail.ch>
This commit is contained in:
Manuel Roth 2023-01-30 10:23:39 +01:00 committed by Andrew Calcutt
parent fc21a43a4d
commit 49f7b99321

View file

@ -6,8 +6,8 @@ import fs from 'node:fs';
import clone from 'clone'; import clone from 'clone';
import glyphCompose from '@mapbox/glyph-pbf-composite'; import glyphCompose from '@mapbox/glyph-pbf-composite';
const getUrlObject = (urlString, req) => { const getUrlObject = (req) => {
const urlObject = new URL(urlString); const urlObject = new URL(`${req.protocol}://${req.headers.host}/`);
// support overriding hostname by sending X-Forwarded-Host http header // support overriding hostname by sending X-Forwarded-Host http header
urlObject.hostname = req.hostname; urlObject.hostname = req.hostname;
@ -19,12 +19,12 @@ export const getPublicUrl = (publicUrl, req) => {
return publicUrl; return publicUrl;
} }
const urlObject = getUrlObject(`${req.protocol}://${req.headers.host}/`, req); const urlObject = getUrlObject(req);
return urlObject.toString(); return urlObject.toString();
}; };
export const getTileUrls = (req, domains, path, format, publicUrl, aliases) => { export const getTileUrls = (req, domains, path, format, publicUrl, aliases) => {
const urlObject = getUrlObject(`${req.protocol}://${req.headers.host}/`, req); const urlObject = getUrlObject(req);
const host = urlObject.host; const host = urlObject.host;
if (domains) { if (domains) {