Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve relative paths to source projects #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fromUri should get the same treatment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


return toUri.protocol + '//' + path.resolve(fromUri.pathname, toUriPathName);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only appropriate for sources that read from the filesystem. In many cases, the protocol may be http:, mapbox:, or tilejson+http(s):, in which case relative resolution doesn't make sense.

Off the top of my head, appropriate protocols are tmsource:, mbtiles:, tilejson:, file:, and <whatever>+file: (possibly bridge:), so these should probably be whitelisted.

https://github.com/mojodna/tilelive-modules/blob/master/index.json contains a mostly complete list of modules to refer to.

}

module.exports = function(_tilelive, options) {
tilelive = _tilelive;

Expand Down