From 49f7b9932151c43cc1d9a0cd9750b0377d0593a6 Mon Sep 17 00:00:00 2001 From: Manuel Roth Date: Mon, 30 Jan 2023 10:23:39 +0100 Subject: [PATCH] fix: improve getUrlObject Signed-off-by: Manuel Roth --- src/utils.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils.js b/src/utils.js index 3c87b01..152bd67 100644 --- a/src/utils.js +++ b/src/utils.js @@ -6,8 +6,8 @@ import fs from 'node:fs'; import clone from 'clone'; import glyphCompose from '@mapbox/glyph-pbf-composite'; -const getUrlObject = (urlString, req) => { - const urlObject = new URL(urlString); +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; @@ -19,12 +19,12 @@ export const getPublicUrl = (publicUrl, req) => { return publicUrl; } - const urlObject = getUrlObject(`${req.protocol}://${req.headers.host}/`, req); + const urlObject = getUrlObject(req); return urlObject.toString(); }; 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; if (domains) {