From 13c481b1ea24da341cb6a1fad981634cbef27147 Mon Sep 17 00:00:00 2001 From: Hermann Schwarting Date: Tue, 16 Jun 2020 11:12:08 +0200 Subject: [PATCH] Support local:// raster tile URLs In the style JSON configuration, allow to use the local:// pseudo-protocol prefix also for raster tile source URLs. When serving the style JSON, rewrite it into an absolute URL using the public URL or the Host header from the request. This allows to use raster tile sources which are served from the same domain, but externally from tileserver-gl. The requests could be handled by a reverse proxy in front of tileserver-gl for example, and redirected to a different service or static files. Instead of hardcoding an absolute host name in the style configuration, using a relative URL allows to use the same style configuration on different hosts and on localhost in the development environment. --- src/serve_style.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/serve_style.js b/src/serve_style.js index ca441db..73294ee 100644 --- a/src/serve_style.js +++ b/src/serve_style.js @@ -40,6 +40,9 @@ module.exports = { for (const name of Object.keys(styleJSON_.sources)) { const source = styleJSON_.sources[name]; source.url = fixUrl(req, source.url, item.publicUrl); + if (source.tiles) { + source.tiles = source.tiles.map(url => fixUrl(req, url, item.publicUrl)) + } } // mapbox-gl-js viewer cannot handle sprite urls with query if (styleJSON_.sprite) {