I have my own OSM server, and then a Tomcat backend for my webapp.
I use leaflet to load tiles like this: http://MAP_SERVER_IP/tiles/{z}/{x}/{y}.png
But I want the request to be made something like: http://APP_SERVER/webapp/validation_servlet?z,x,y
This way 'validation_servlet' can validate the request and then make the response to be the content of the real url: http://MAP_SERVER_IP/tiles/{z}/{x}/{y}.png
I tried using redirection, but it seems that leaflet does not follow redirects.
This code is the response of the validation_servlet:
<html><head><meta http-equiv="refresh" content="0; url=http://MAP_SERVER_IP/tiles/'+trim(&x)+'/'+trim(&y)+'/'+trim(&z)+'.png" /></head></html>
Where &x, &y and &z are the parameters received from the leaflet request. That URL works fine in a browser, and redirection is followed. But from leaflet it does not.
Also i do not want the APP_SERVER to download the tile to then serve it.
The objective is to 'secure' access to my tile server. So the real tile URL should never be seen.
Any ideas???
Thanks in advance!
Simply define your L.TileLayer
like:
var tiles = L.tileLayer('http://APP_SERVER/webapp/validation_servlet?{z},{x},{y}');
tiles.addTo(map);
You also point out:
The objective is to 'secure' access to my tile server. So the real tile URL should never be seen.
[...]
Also i do not want the APP_SERVER to download the tile to then serve it.
Please note that these two goals are not achievable together. Either you proxy the tile (fetching it from your APP_SERVER
and obscuring its source), or you redirect to the tile (saving your APP_SERVER
some bandwidth and resources but sending the final tile URL to the browser).