Allowing tile urls to carry the query params from the original request
This commit is contained in:
parent
042b8b986a
commit
a120435257
1 changed files with 24 additions and 1 deletions
|
|
@ -24,9 +24,25 @@ const fixUrl = (req, url, publicUrl, opt_nokey) => {
|
||||||
query = `?${queryParams.join('&')}`;
|
query = `?${queryParams.join('&')}`;
|
||||||
}
|
}
|
||||||
return url.replace(
|
return url.replace(
|
||||||
'local://', utils.getPublicUrl(publicUrl, req)) + query;
|
'local://', utils.getPublicUrl(publicUrl, req)) + + getQuery(req, opt_nokey);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Return the query suffix from the original request
|
||||||
|
const getQuery = (req, opt_nokey) => {
|
||||||
|
const queryParams = [];
|
||||||
|
if (!opt_nokey && req.query.key) {
|
||||||
|
queryParams.unshift(`key=${encodeURIComponent(req.query.key)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let query = '';
|
||||||
|
if (queryParams.length) {
|
||||||
|
query = `?${queryParams.join('&')}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init: (options, repo) => {
|
init: (options, repo) => {
|
||||||
const app = express().disable('x-powered-by');
|
const app = express().disable('x-powered-by');
|
||||||
|
|
@ -40,6 +56,13 @@ module.exports = {
|
||||||
for (const name of Object.keys(styleJSON_.sources)) {
|
for (const name of Object.keys(styleJSON_.sources)) {
|
||||||
const source = styleJSON_.sources[name];
|
const source = styleJSON_.sources[name];
|
||||||
source.url = fixUrl(req, source.url, item.publicUrl);
|
source.url = fixUrl(req, source.url, item.publicUrl);
|
||||||
|
|
||||||
|
// Apply the query parameters to the tile urls
|
||||||
|
if (source.tiles) {
|
||||||
|
for (let i = 0; i < source.tiles.length; i++) {
|
||||||
|
source.tiles[i] = source.tiles[i] + getQuery(req);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// mapbox-gl-js viewer cannot handle sprite urls with query
|
// mapbox-gl-js viewer cannot handle sprite urls with query
|
||||||
if (styleJSON_.sprite) {
|
if (styleJSON_.sprite) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue