Skip to content

Commit 626faed

Browse files
authored
fix: fix CORS error when using transformed mapbox source URL (#48)
Adds a `secure` search param to transformed Mapbox source URLs, which prevents CORS issues when used by the map client.
1 parent aa2d3ba commit 626faed

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/lib/style.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,7 @@ function normalizeSource(uri: MapboxURI, accessToken?: string) {
118118
result.searchParams.set('access_token', accessToken)
119119
}
120120

121+
result.searchParams.set('secure', '')
122+
121123
return result.href
122124
}

test/style.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('transformUrls()', () => {
8383
expect(streetsV12.sources).toStrictEqual({
8484
composite: {
8585
type: 'vector',
86-
url: 'https://api.mapbox.com/v4/mapbox.mapbox-streets-v8,mapbox.mapbox-terrain-v2,mapbox.mapbox-bathymetry-v2.json',
86+
url: 'https://api.mapbox.com/v4/mapbox.mapbox-streets-v8,mapbox.mapbox-terrain-v2,mapbox.mapbox-bathymetry-v2.json?secure=',
8787
},
8888
})
8989
})
@@ -115,7 +115,7 @@ describe('transformUrls()', () => {
115115
expect(streetsV12.sources).toStrictEqual({
116116
composite: {
117117
type: 'vector',
118-
url: `https://api.mapbox.com/v4/mapbox.mapbox-streets-v8,mapbox.mapbox-terrain-v2,mapbox.mapbox-bathymetry-v2.json?access_token=${accessToken}`,
118+
url: `https://api.mapbox.com/v4/mapbox.mapbox-streets-v8,mapbox.mapbox-terrain-v2,mapbox.mapbox-bathymetry-v2.json?access_token=${accessToken}&secure=`,
119119
},
120120
})
121121
})

0 commit comments

Comments
 (0)