dummy rewrite url fix

This commit is contained in:
Stepan Kuzmin 2018-01-24 19:26:01 +03:00
parent e187a9ace7
commit c8d46d398a

View File

@ -3,7 +3,7 @@ use iron::headers::{Headers, parsing};
use iron::prelude::{Plugin}; use iron::prelude::{Plugin};
use mapbox_expressions_to_sql; use mapbox_expressions_to_sql;
use persistent::Read; use persistent::Read;
use regex::Captures; use regex::{Regex, Captures};
use serde_json; use serde_json;
use urlencoded::UrlEncodedQuery; use urlencoded::UrlEncodedQuery;
@ -44,15 +44,14 @@ pub fn tileset(req: &mut Request, caps: Captures) -> IronResult<Response> {
format!("{}:{}", host, port) format!("{}:{}", host, port)
}; };
let path = req.url.path(); let original_url = get_header(&req.headers, "x-rewrite-url", &req.url.path().join("/"));
let uri = if path.len() > 1 { let re = Regex::new(r"\A(.*)\.json\z").unwrap();
path.split_last().map(|(_, elements)| elements.join("/")).unwrap() let uri = match re.captures(&original_url) {
} else { Some(caps) => caps[1].to_string(),
caps["tileset"].to_string() None => return Ok(Response::with((status::InternalServerError)))
}; };
let original_url = get_header(&req.headers, "x-rewrite-url", &uri); let tiles_url = format!("{}://{}/{}/{{z}}/{{x}}/{{y}}.pbf", protocol, host_and_port, uri);
let tiles_url = format!("{}://{}/{}/{{z}}/{{x}}/{{y}}.pbf", protocol, host_and_port, original_url);
let mut tilejson_builder = TileJSONBuilder::new(); let mut tilejson_builder = TileJSONBuilder::new();
tilejson_builder.scheme("tms"); tilejson_builder.scheme("tms");