Skip to content

Commit

Permalink
Merge pull request #22 from mapzen/configurable-formats
Browse files Browse the repository at this point in the history
Allow configuration of formats to handle
  • Loading branch information
rmarianski committed Mar 21, 2016
2 parents 706857c + 168a1a3 commit 13abdfa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions config.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ queries:
config: ../vector-datasource/queries.yaml
template-path: ../vector-datasource/queries
reload-templates: true
formats: [json, topojson, mvt]
server:
host: localhost
port: 8080
Expand Down
30 changes: 21 additions & 9 deletions tileserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def coord_is_valid(coord):
RequestData = namedtuple('RequestData', 'layer_spec coord format')


def parse_request_path(path):
def parse_request_path(path, extensions_to_handle):
"""given a path, parse the underlying layer, coordinate, and format"""
parts = path.split('/')
if len(parts) != 5:
Expand All @@ -49,9 +49,10 @@ def parse_request_path(path):
if len(row_fields) != 2:
return None
row_str, ext = row_fields
format = extension_to_format.get(ext)
if format is None:
if ext not in extensions_to_handle:
return None
format = extension_to_format.get(ext)
assert format, 'Unknown extension %s' % ext
try:
zoom = int(zoom_str)
column = int(column_str)
Expand Down Expand Up @@ -170,10 +171,11 @@ class TileServer(object):
# we want this during development, but not during production
propagate_errors = False

def __init__(self, layer_config, data_fetcher, post_process_data,
io_pool, store, redis_cache_index, sqs_queue,
health_checker=None):
def __init__(self, layer_config, extensions, data_fetcher,
post_process_data, io_pool, store, redis_cache_index,
sqs_queue, health_checker=None):
self.layer_config = layer_config
self.extensions = extensions
self.data_fetcher = data_fetcher
self.post_process_data = post_process_data
self.io_pool = io_pool
Expand Down Expand Up @@ -212,7 +214,7 @@ def handle_request(self, request):
if (self.health_checker and
self.health_checker.is_health_check(request)):
return self.health_checker(request)
request_data = parse_request_path(request.path)
request_data = parse_request_path(request.path, self.extensions)
if request_data is None:
return self.generate_404()
layer_spec = request_data.layer_spec
Expand Down Expand Up @@ -441,6 +443,16 @@ def create_tileserver_from_config(config):
template_path = query_config['template-path']
reload_templates = query_config['reload-templates']

extensions_config = config.get('formats')
extensions = set()
if extensions_config:
for extension in extensions_config:
assert extension in extension_to_format, \
'Unknown format: %s' % extension
extensions.add(extension)
else:
extensions = set(['json', 'topojson', 'mvt'])

with open(queries_config_path) as query_cfg_fp:
queries_config = yaml.load(query_cfg_fp)
all_layer_data, layer_data, post_process_data = parse_layer_data(
Expand Down Expand Up @@ -488,8 +500,8 @@ def create_tileserver_from_config(config):
health_checker = HealthChecker(health_check_url, conn_info)

tile_server = TileServer(
layer_config, data_fetcher, post_process_data, io_pool, store,
redis_cache_index, sqs_queue, health_checker)
layer_config, extensions, data_fetcher, post_process_data, io_pool,
store, redis_cache_index, sqs_queue, health_checker)
return tile_server


Expand Down

0 comments on commit 13abdfa

Please sign in to comment.