diff --git a/src/util/mapbox.js b/src/util/mapbox.js index eebe86194db..2619132f371 100644 --- a/src/util/mapbox.js +++ b/src/util/mapbox.js @@ -17,6 +17,10 @@ function makeAPIURL(urlObject: UrlObject, accessToken: string | null | void): st urlObject.protocol = apiUrlObject.protocol; urlObject.authority = apiUrlObject.authority; + if (apiUrlObject.path !== '/') { + urlObject.path = `${apiUrlObject.path}${urlObject.path}`; + } + if (!config.REQUIRE_ACCESS_TOKEN) return formatUrl(urlObject); accessToken = accessToken || config.ACCESS_TOKEN; diff --git a/test/unit/util/mapbox.test.js b/test/unit/util/mapbox.test.js index ad08fb943a1..da8c5b4798c 100644 --- a/test/unit/util/mapbox.test.js +++ b/test/unit/util/mapbox.test.js @@ -30,6 +30,17 @@ test("mapbox", (t) => { t.end(); }); + t.test('handles custom API_URLs with paths', (t) => { + const previousUrl = config.API_URL; + config.API_URL = 'https://test.example.com/api.mapbox.com'; + t.equal( + mapbox.normalizeStyleURL('mapbox://styles/foo/bar'), + 'https://test.example.com/api.mapbox.com/styles/v1/foo/bar?access_token=key' + ); + config.API_URL = previousUrl; + t.end(); + }); + t.end(); }); @@ -73,6 +84,17 @@ test("mapbox", (t) => { t.end(); }); + t.test('handles custom API_URLs with paths', (t) => { + const previousUrl = config.API_URL; + config.API_URL = 'https://test.example.com/api.mapbox.com'; + t.equal( + mapbox.normalizeSourceURL('mapbox://one.a'), + 'https://test.example.com/api.mapbox.com/v4/one.a.json?secure&access_token=key' + ); + config.API_URL = previousUrl; + t.end(); + }); + t.end(); }); @@ -92,6 +114,17 @@ test("mapbox", (t) => { t.end(); }); + t.test('handles custom API_URLs with paths', (t) => { + const previousUrl = config.API_URL; + config.API_URL = 'https://test.example.com/api.mapbox.com'; + t.equal( + mapbox.normalizeGlyphsURL('mapbox://fonts/boxmap/{fontstack}/{range}.pbf'), + 'https://test.example.com/api.mapbox.com/fonts/v1/boxmap/{fontstack}/{range}.pbf?access_token=key' + ); + config.API_URL = previousUrl; + t.end(); + }); + t.end(); }); @@ -149,6 +182,17 @@ test("mapbox", (t) => { t.end(); }); + t.test('handles custom API_URLs with paths', (t) => { + const previousUrl = config.API_URL; + config.API_URL = 'https://test.example.com/api.mapbox.com'; + t.equal( + mapbox.normalizeSpriteURL('mapbox://sprites/mapbox/streets-v8', '', '.json'), + 'https://test.example.com/api.mapbox.com/styles/v1/mapbox/streets-v8/sprite.json?access_token=key' + ); + config.API_URL = previousUrl; + t.end(); + }); + t.end(); });