tileserver-gl 4.4.3 → 4.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/utils.js CHANGED
@@ -6,19 +6,35 @@ import fs from 'node:fs';
6
6
  import clone from 'clone';
7
7
  import glyphCompose from '@mapbox/glyph-pbf-composite';
8
8
 
9
- export const getPublicUrl = (publicUrl, req) =>
10
- publicUrl || `${req.protocol}://${req.headers.host}/`;
9
+ /**
10
+ * Generate new URL object
11
+ * @params {object} req - Express request
12
+ * @returns {URL} object
13
+ **/
14
+ const getUrlObject = (req) => {
15
+ const urlObject = new URL(`${req.protocol}://${req.headers.host}/`);
16
+ // support overriding hostname by sending X-Forwarded-Host http header
17
+ urlObject.hostname = req.hostname;
18
+ return urlObject;
19
+ };
20
+
21
+ export const getPublicUrl = (publicUrl, req) => {
22
+ if (publicUrl) {
23
+ return publicUrl;
24
+ }
25
+ return getUrlObject(req).toString();
26
+ };
11
27
 
12
28
  export const getTileUrls = (req, domains, path, format, publicUrl, aliases) => {
29
+ const urlObject = getUrlObject(req);
13
30
  if (domains) {
14
31
  if (domains.constructor === String && domains.length > 0) {
15
32
  domains = domains.split(',');
16
33
  }
17
- const host = req.headers.host;
18
- const hostParts = host.split('.');
34
+ const hostParts = urlObject.host.split('.');
19
35
  const relativeSubdomainsUsable =
20
36
  hostParts.length > 1 &&
21
- !/^([0-9]{1,3}\.){3}[0-9]{1,3}(\:[0-9]+)?$/.test(host);
37
+ !/^([0-9]{1,3}\.){3}[0-9]{1,3}(\:[0-9]+)?$/.test(urlObject.host);
22
38
  const newDomains = [];
23
39
  for (const domain of domains) {
24
40
  if (domain.indexOf('*') !== -1) {
@@ -34,7 +50,7 @@ export const getTileUrls = (req, domains, path, format, publicUrl, aliases) => {
34
50
  domains = newDomains;
35
51
  }
36
52
  if (!domains || domains.length == 0) {
37
- domains = [req.headers.host];
53
+ domains = [urlObject.host];
38
54
  }
39
55
 
40
56
  const queryParams = [];