From 2d9e2f7f4e268f3590ef3387ee5efa77ab7353e2 Mon Sep 17 00:00:00 2001 From: Oleksandr Shyshatskyi Date: Thu, 15 Sep 2022 20:23:48 +0300 Subject: [PATCH 1/2] Improved publicUrl option support In WMTS the publicUrl path was missed and it was not working properly. Similar story about wmts.tmpl: the baseUrl is not working properly when tileserver is hidden behind the proxy with different root path. --- public/templates/index.tmpl | 2 +- src/server.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/public/templates/index.tmpl b/public/templates/index.tmpl index 603f2eb04..297520e5c 100644 --- a/public/templates/index.tmpl +++ b/public/templates/index.tmpl @@ -41,7 +41,7 @@ {{#if serving_data}}| {{/if}}TileJSON {{/if}} {{#if serving_rendered}} - | WMTS + | WMTS {{/if}} {{#if xyz_link}} | XYZ diff --git a/src/server.js b/src/server.js index 9fedc02d6..70180d77e 100644 --- a/src/server.js +++ b/src/server.js @@ -419,7 +419,12 @@ function start(opts) { } wmts.id = id; wmts.name = (serving.styles[id] || serving.rendered[id]).name; - wmts.baseUrl = `${req.get('X-Forwarded-Protocol') ? req.get('X-Forwarded-Protocol') : req.protocol}://${req.get('host')}`; + if (opts.publicUrl) { + wmts.baseUrl = opts.publicUrl; + } + else { + wmts.baseUrl = `${req.get('X-Forwarded-Protocol') ? req.get('X-Forwarded-Protocol') : req.protocol}://${req.get('host')}`; + } return wmts; }); From ac7707294c28b0ed9c5db9c9c259b3ab63f95d25 Mon Sep 17 00:00:00 2001 From: Oleksandr Shyshatskyi Date: Thu, 15 Sep 2022 20:36:52 +0300 Subject: [PATCH 2/2] Minor bugfix: make baseUrl always use '/' in the end --- public/templates/wmts.tmpl | 8 ++++---- src/server.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/public/templates/wmts.tmpl b/public/templates/wmts.tmpl index 683c3ac84..0db7349c0 100644 --- a/public/templates/wmts.tmpl +++ b/public/templates/wmts.tmpl @@ -11,7 +11,7 @@ - + RESTful @@ -24,7 +24,7 @@ - + RESTful @@ -50,7 +50,7 @@ GoogleMapsCompatible - + GoogleMapsCompatible GoogleMapsCompatible EPSG:3857 @@ -403,5 +403,5 @@ 262144 - + diff --git a/src/server.js b/src/server.js index 70180d77e..1e0e02b09 100644 --- a/src/server.js +++ b/src/server.js @@ -423,7 +423,7 @@ function start(opts) { wmts.baseUrl = opts.publicUrl; } else { - wmts.baseUrl = `${req.get('X-Forwarded-Protocol') ? req.get('X-Forwarded-Protocol') : req.protocol}://${req.get('host')}`; + wmts.baseUrl = `${req.get('X-Forwarded-Protocol') ? req.get('X-Forwarded-Protocol') : req.protocol}://${req.get('host')}/`; } return wmts; });