fix: fix support for overriding hostname by setting X-Forwarded-Host http header
Signed-off-by: Manuel Roth <manuelroth@hotmail.ch>
This commit is contained in:
parent
00a536f9fb
commit
fc21a43a4d
1 changed files with 20 additions and 4 deletions
24
src/utils.js
24
src/utils.js
|
|
@ -6,15 +6,31 @@ 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';
|
||||||
|
|
||||||
export const getPublicUrl = (publicUrl, req) =>
|
const getUrlObject = (urlString, req) => {
|
||||||
publicUrl || `${req.protocol}://${req.headers.host}/`;
|
const urlObject = new URL(urlString);
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
const urlObject = getUrlObject(`${req.protocol}://${req.headers.host}/`, req);
|
||||||
|
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 host = urlObject.host;
|
||||||
|
|
||||||
if (domains) {
|
if (domains) {
|
||||||
if (domains.constructor === String && domains.length > 0) {
|
if (domains.constructor === String && domains.length > 0) {
|
||||||
domains = domains.split(',');
|
domains = domains.split(',');
|
||||||
}
|
}
|
||||||
const host = req.headers.host;
|
|
||||||
const hostParts = host.split('.');
|
const hostParts = host.split('.');
|
||||||
const relativeSubdomainsUsable =
|
const relativeSubdomainsUsable =
|
||||||
hostParts.length > 1 &&
|
hostParts.length > 1 &&
|
||||||
|
|
@ -34,7 +50,7 @@ export const getTileUrls = (req, domains, path, format, publicUrl, aliases) => {
|
||||||
domains = newDomains;
|
domains = newDomains;
|
||||||
}
|
}
|
||||||
if (!domains || domains.length == 0) {
|
if (!domains || domains.length == 0) {
|
||||||
domains = [req.headers.host];
|
domains = [host];
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryParams = [];
|
const queryParams = [];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue