diff --git a/index.js b/index.js index a0ce4f9..a57feff 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,18 @@ 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); + const fromUriPathName = path.join(fromUri.hostname, fromUri.path); + + return toUri.protocol + '//' + path.resolve(fromUriPathName, toUriPathName); +} + module.exports = function(_tilelive, options) { tilelive = _tilelive;