Skip to content

Commit

Permalink
fix(geocoder): Add fetch options to support custom headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Jun 3, 2020
1 parent d4ed4bc commit ffdbf2e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/geocoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": {
"@conveyal/geocoder-arcgis-geojson": "^0.0.2",
"@conveyal/lonlat": "^1.4.0",
"isomorphic-mapzen-search": "^1.4.1",
"isomorphic-mapzen-search": "^1.5.1",
"lodash.memoize": "^4.1.2"
},
"gitHead": "644c72e0d08f8daf93b44eaf0deec88a1e16f414"
Expand Down
21 changes: 18 additions & 3 deletions packages/geocoder/src/geocoders/abstract-geocoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,18 @@ export default class Geocoder {
* Default autocomplete query generator
*/
getAutocompleteQuery(query) {
const { apiKey, baseUrl, boundary, focusPoint } = this.geocoderConfig;
const {
apiKey,
baseUrl,
boundary,
focusPoint,
options
} = this.geocoderConfig;
return {
apiKey,
boundary,
focusPoint,
options,
url: baseUrl ? `${baseUrl}/autocomplete` : undefined,
...query
};
Expand All @@ -77,10 +84,11 @@ export default class Geocoder {
* Default reverse query generator
*/
getReverseQuery(query) {
const { apiKey, baseUrl } = this.geocoderConfig;
const { apiKey, baseUrl, options } = this.geocoderConfig;
return {
apiKey,
format: true,
options,
url: baseUrl ? `${baseUrl}/reverse` : undefined,
...query
};
Expand All @@ -90,11 +98,18 @@ export default class Geocoder {
* Default search query generator.
*/
getSearchQuery(query) {
const { apiKey, baseUrl, boundary, focusPoint } = this.geocoderConfig;
const {
apiKey,
baseUrl,
boundary,
focusPoint,
options
} = this.geocoderConfig;
return {
apiKey,
boundary,
focusPoint,
options,
url: baseUrl ? `${baseUrl}/search` : undefined,
format: false, // keep as returned GeoJSON,
...query
Expand Down
4 changes: 4 additions & 0 deletions packages/geocoder/src/geocoders/pelias.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export default class PeliasGeocoder extends Geocoder {
baseUrl,
boundary,
focusPoint,
options,
sources
} = this.geocoderConfig;
return {
apiKey,
boundary,
focusPoint,
options,
// explicitly send over null for sources if provided sources is not truthy
// in order to avoid default isomorphic-mapzen-search sources form being
// applied
Expand All @@ -42,12 +44,14 @@ export default class PeliasGeocoder extends Geocoder {
baseUrl,
boundary,
focusPoint,
options,
sources
} = this.geocoderConfig;
return {
apiKey,
boundary,
focusPoint,
options,
// explicitly send over null for sources if provided sources is not truthy
// in order to avoid default isomorphic-mapzen-search sources form being
// applied
Expand Down
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8317,9 +8317,10 @@ isomorphic-fetch@^2.1.1, isomorphic-fetch@^2.2.1:
node-fetch "^1.0.1"
whatwg-fetch ">=0.10.0"

isomorphic-mapzen-search@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/isomorphic-mapzen-search/-/isomorphic-mapzen-search-1.4.1.tgz#914b85d16c23ac0d1e8fb0c90c3ff12503b1c577"
isomorphic-mapzen-search@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/isomorphic-mapzen-search/-/isomorphic-mapzen-search-1.5.1.tgz#5ac0214cec436fb550e8ef362cf8d11b17de8e9c"
integrity sha512-38GcjidOqjVQkUzDovx+ceUXHwOliIoFq+qJ/zUzaZwn2h8qEANLMTjaZkFvYN2XdSGB65zBOH5n/iP/Vs1ejA==
dependencies:
"@conveyal/lonlat" "^1.1.2"
isomorphic-fetch "^2.2.1"
Expand Down

0 comments on commit ffdbf2e

Please sign in to comment.