From c0b7b54eb083056c82ce64eeb0c4de88d328e937 Mon Sep 17 00:00:00 2001 From: Edan Schwartz Date: Fri, 29 Apr 2016 11:42:58 -0500 Subject: [PATCH 1/2] Resolve relative paths to source projects eg. `tmsource://../../project.tm2source` --- index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.js b/index.js index a0ce4f9..ad8b9f2 100644 --- a/index.js +++ b/index.js @@ -55,6 +55,9 @@ var style = function(uri, callback) { // override properties if necessary data.scale = +uri.query.scale || data.scale; + // Resolve relative path to data source + data.source = resolveTileliveUri(uri, url.parse(data.source)); + return style.toXML(data, function(err, xml) { if (err) { return callback(err); @@ -225,6 +228,17 @@ style.registerProtocols = function(tilelive) { tilelive.protocols["tmstyle:"] = this; }; +function resolveTileliveUri(fromUri, toUri) { + // Normalize uris + fromUri = url.parse(fromUri); + toUri = url.parse(toUri); + + // Url.parse reads the first ".." as the hostname + const toUriPathName = path.join(toUri.hostname, toUri.path); + + return toUri.protocol + '//' + path.resolve(fromUri.pathname, toUriPathName); +} + module.exports = function(_tilelive, options) { tilelive = _tilelive; From 9778b875dfcd9d8ab49f91a613f5ea7fbabb04da Mon Sep 17 00:00:00 2001 From: Edan Schwartz Date: Mon, 9 May 2016 09:47:37 -0500 Subject: [PATCH 2/2] Resolving relative paths: fix `fromUri` pathname --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ad8b9f2..a57feff 100644 --- a/index.js +++ b/index.js @@ -235,8 +235,9 @@ function resolveTileliveUri(fromUri, toUri) { // Url.parse reads the first ".." as the hostname const toUriPathName = path.join(toUri.hostname, toUri.path); + const fromUriPathName = path.join(fromUri.hostname, fromUri.path); - return toUri.protocol + '//' + path.resolve(fromUri.pathname, toUriPathName); + return toUri.protocol + '//' + path.resolve(fromUriPathName, toUriPathName); } module.exports = function(_tilelive, options) {