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
fix #127
  • Loading branch information
landonreed committed Feb 13, 2020
1 parent 1210661 commit 4a6a64b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 52 deletions.
4 changes: 4 additions & 0 deletions example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ geocoder:
focusPoint:
lat: 45.5223452
lon: -122.6821804
# Custom fetch options to pass to geocoder resource.
# options:
# headers:
# x-custom-header: abc123
# required geocoder type.
type: PELIAS
# This base URL is required as the libraries will default to using now-defunct
Expand Down
15 changes: 10 additions & 5 deletions lib/util/geocoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ class Geocoder {
* Default autocomplete query generator
*/
getAutocompleteQuery (query) {
const {apiKey, baseUrl, boundary, focusPoint} = this.geocoderConfig
const {apiKey, baseUrl, boundary, options, focusPoint} = this.geocoderConfig
return {
apiKey,
boundary,
focusPoint,
options,
url: baseUrl ? `${baseUrl}/autocomplete` : undefined,
...query
}
Expand All @@ -76,10 +77,11 @@ 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 @@ -89,11 +91,12 @@ 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 Expand Up @@ -245,11 +248,12 @@ export class PeliasGeocoder extends Geocoder {
* `sources` parameter is a Pelias-specific option.
*/
getAutocompleteQuery (query) {
const {apiKey, baseUrl, boundary, focusPoint, sources} = this.geocoderConfig
const {apiKey, 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 @@ -264,14 +268,15 @@ export class PeliasGeocoder extends Geocoder {
* `sources` parameter is a Pelias-specific option.
*/
getSearchQuery (query) {
const {apiKey, baseUrl, boundary, focusPoint, sources} = this.geocoderConfig
const {apiKey, baseUrl, boundary, focusPoint, options, sources} = this.geocoderConfig
return {
apiKey,
boundary,
focusPoint,
// explicitly send over null for sources if provided sources is not truthy
// in order to avoid default isomorphic-mapzen-search sources form being
// applied
options,
sources: sources || null,
url: baseUrl ? `${baseUrl}/search` : undefined,
format: false, // keep as returned GeoJSON,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"history": "^4.7.2",
"immutability-helper": "^2.1.1",
"isomorphic-fetch": "^2.2.1",
"isomorphic-mapzen-search": "^1.4.1",
"isomorphic-mapzen-search": "^1.5.1",
"leaflet": "^1.5.1",
"leaflet.polylinemeasure": "github:ppete2/Leaflet.PolylineMeasure",
"lodash.debounce": "^4.0.8",
Expand Down
52 changes: 6 additions & 46 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4756,7 +4756,7 @@ debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1:
dependencies:
ms "^2.1.1"

debuglog@*, debuglog@^1.0.1:
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
Expand Down Expand Up @@ -7139,7 +7139,7 @@ import-local@^2.0.0:
pkg-dir "^3.0.0"
resolve-cwd "^2.0.0"

imurmurhash@*, imurmurhash@^0.1.4:
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
Expand Down Expand Up @@ -7842,10 +7842,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"
integrity sha512-5OMaWf3DOU/e2mzU6Q5yCRP9KxMoEX2+tfeZwTWyi3NTKB8pl2nf/dR1XjJ5DpCPlpLWwv8CoBiigeyP7ShmZw==
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 Expand Up @@ -8824,11 +8824,6 @@ lockfile@^1.0.4:
dependencies:
signal-exit "^3.0.2"

lodash._baseindexof@*:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=

lodash._baseuniq@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
Expand All @@ -8837,23 +8832,6 @@ lodash._baseuniq@~4.6.0:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"

lodash._bindcallback@*:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=

lodash._cacheindexof@*:
version "3.0.2"
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=

lodash._createcache@*:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
dependencies:
lodash._getnative "^3.0.0"

lodash._createcompounder@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._createcompounder/-/lodash._createcompounder-3.0.0.tgz#5dd2cb55372d6e70e0e2392fb2304d6631091075"
Expand All @@ -8867,11 +8845,6 @@ lodash._createset@~4.0.0:
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=

lodash._getnative@*, lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=

lodash._reinterpolate@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
Expand Down Expand Up @@ -8991,11 +8964,6 @@ lodash.omit@^4.0.1:
resolved "https://registry.yarnpkg.com/lodash.omit/-/lodash.omit-4.5.0.tgz#6eb19ae5a1ee1dd9df0b969e66ce0b7fa30b5e60"
integrity sha1-brGa5aHuHdnfC5aeZs4Lf6MLXmA=

lodash.restparam@*:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=

lodash.set@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
Expand Down Expand Up @@ -10236,7 +10204,6 @@ npm@^6.8.0:
cmd-shim "^3.0.3"
columnify "~1.5.4"
config-chain "^1.1.12"
debuglog "*"
detect-indent "~5.0.0"
detect-newline "^2.1.0"
dezalgo "~1.0.3"
Expand All @@ -10251,7 +10218,6 @@ npm@^6.8.0:
has-unicode "~2.0.1"
hosted-git-info "^2.8.5"
iferr "^1.0.2"
imurmurhash "*"
infer-owner "^1.0.4"
inflight "~1.0.6"
inherits "^2.0.4"
Expand All @@ -10270,14 +10236,8 @@ npm@^6.8.0:
libnpx "^10.2.0"
lock-verify "^2.1.0"
lockfile "^1.0.4"
lodash._baseindexof "*"
lodash._baseuniq "~4.6.0"
lodash._bindcallback "*"
lodash._cacheindexof "*"
lodash._createcache "*"
lodash._getnative "*"
lodash.clonedeep "~4.5.0"
lodash.restparam "*"
lodash.union "~4.6.0"
lodash.uniq "~4.5.0"
lodash.without "~4.4.0"
Expand Down

0 comments on commit 4a6a64b

Please sign in to comment.