Skip to content
This repository was archived by the owner on Dec 3, 2018. It is now read-only.
This repository was archived by the owner on Dec 3, 2018. It is now read-only.

Middleware drops host part of source URI #1288

Description

@zerebubuth

In lib/middleware.js, the function normalizePaths drops the host portion of the URI for the id and source entries in the body object. This means that if your source is a remote TileJSON URI on a different host, then any attempt to save the style results in an error saying "Invalid URL".

For the specific case that I am experiencing, the patch below fixes it. However, I assume normalizePaths was dropping the host for a reason, so perhaps this is not an appropriate fix for everyone (refs #1278), but I'd like to try and find a fix which allows us to use remote TileJSON sources.

diff --git a/lib/middleware.js b/lib/middleware.js
index c723d63..59438c2 100644
--- a/lib/middleware.js
+++ b/lib/middleware.js
@@ -22,7 +22,7 @@ middleware.normalizePaths = function(req, res, next) {
     ['id','source'].forEach(function(key) {
         if (!req.body || !req.body[key]) return;
         var uri = tm.parse(req.body[key]);
-        req.body[key] = (uri.protocol ? uri.protocol + '//' : '') + uri.dirname;
+        req.body[key] = (uri.protocol ? uri.protocol + '//' : '') + uri.host + uri.dirname;
     });
     next();
 };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions