Skip to content

Commit 3b7694a

Browse files
authored
Merge pull request #128 from opentripplanner/add-geocode-fetch-options
Add fetch options to support custom headers
2 parents 1c0022a + 4a6a64b commit 3b7694a

File tree

4 files changed

+21
-52
lines changed

4 files changed

+21
-52
lines changed

Diff for: example-config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ geocoder:
5353
focusPoint:
5454
lat: 45.5223452
5555
lon: -122.6821804
56+
# Custom fetch options to pass to geocoder resource.
57+
# options:
58+
# headers:
59+
# x-custom-header: abc123
5660
# required geocoder type.
5761
type: PELIAS
5862
# This base URL is required as the libraries will default to using now-defunct

Diff for: lib/util/geocoder.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ class Geocoder {
6262
* Default autocomplete query generator
6363
*/
6464
getAutocompleteQuery (query) {
65-
const {apiKey, baseUrl, boundary, focusPoint} = this.geocoderConfig
65+
const {apiKey, baseUrl, boundary, options, focusPoint} = this.geocoderConfig
6666
return {
6767
apiKey,
6868
boundary,
6969
focusPoint,
70+
options,
7071
url: baseUrl ? `${baseUrl}/autocomplete` : undefined,
7172
...query
7273
}
@@ -76,10 +77,11 @@ class Geocoder {
7677
* Default reverse query generator
7778
*/
7879
getReverseQuery (query) {
79-
const {apiKey, baseUrl} = this.geocoderConfig
80+
const {apiKey, baseUrl, options} = this.geocoderConfig
8081
return {
8182
apiKey,
8283
format: true,
84+
options,
8385
url: baseUrl ? `${baseUrl}/reverse` : undefined,
8486
...query
8587
}
@@ -89,11 +91,12 @@ class Geocoder {
8991
* Default search query generator.
9092
*/
9193
getSearchQuery (query) {
92-
const {apiKey, baseUrl, boundary, focusPoint} = this.geocoderConfig
94+
const {apiKey, baseUrl, boundary, focusPoint, options} = this.geocoderConfig
9395
return {
9496
apiKey,
9597
boundary,
9698
focusPoint,
99+
options,
97100
url: baseUrl ? `${baseUrl}/search` : undefined,
98101
format: false, // keep as returned GeoJSON,
99102
...query
@@ -245,11 +248,12 @@ export class PeliasGeocoder extends Geocoder {
245248
* `sources` parameter is a Pelias-specific option.
246249
*/
247250
getAutocompleteQuery (query) {
248-
const {apiKey, baseUrl, boundary, focusPoint, sources} = this.geocoderConfig
251+
const {apiKey, baseUrl, boundary, focusPoint, options, sources} = this.geocoderConfig
249252
return {
250253
apiKey,
251254
boundary,
252255
focusPoint,
256+
options,
253257
// explicitly send over null for sources if provided sources is not truthy
254258
// in order to avoid default isomorphic-mapzen-search sources form being
255259
// applied
@@ -264,14 +268,15 @@ export class PeliasGeocoder extends Geocoder {
264268
* `sources` parameter is a Pelias-specific option.
265269
*/
266270
getSearchQuery (query) {
267-
const {apiKey, baseUrl, boundary, focusPoint, sources} = this.geocoderConfig
271+
const {apiKey, baseUrl, boundary, focusPoint, options, sources} = this.geocoderConfig
268272
return {
269273
apiKey,
270274
boundary,
271275
focusPoint,
272276
// explicitly send over null for sources if provided sources is not truthy
273277
// in order to avoid default isomorphic-mapzen-search sources form being
274278
// applied
279+
options,
275280
sources: sources || null,
276281
url: baseUrl ? `${baseUrl}/search` : undefined,
277282
format: false, // keep as returned GeoJSON,

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"history": "^4.7.2",
4545
"immutability-helper": "^2.1.1",
4646
"isomorphic-fetch": "^2.2.1",
47-
"isomorphic-mapzen-search": "^1.4.1",
47+
"isomorphic-mapzen-search": "^1.5.1",
4848
"leaflet": "^1.5.1",
4949
"leaflet.polylinemeasure": "github:ppete2/Leaflet.PolylineMeasure",
5050
"lodash.debounce": "^4.0.8",

Diff for: yarn.lock

+6-46
Original file line numberDiff line numberDiff line change
@@ -4756,7 +4756,7 @@ debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1:
47564756
dependencies:
47574757
ms "^2.1.1"
47584758

4759-
debuglog@*, debuglog@^1.0.1:
4759+
debuglog@^1.0.1:
47604760
version "1.0.1"
47614761
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
47624762
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
@@ -7139,7 +7139,7 @@ import-local@^2.0.0:
71397139
pkg-dir "^3.0.0"
71407140
resolve-cwd "^2.0.0"
71417141

7142-
imurmurhash@*, imurmurhash@^0.1.4:
7142+
imurmurhash@^0.1.4:
71437143
version "0.1.4"
71447144
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
71457145
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
@@ -7842,10 +7842,10 @@ isomorphic-fetch@^2.1.1, isomorphic-fetch@^2.2.1:
78427842
node-fetch "^1.0.1"
78437843
whatwg-fetch ">=0.10.0"
78447844

7845-
isomorphic-mapzen-search@^1.4.1:
7846-
version "1.4.1"
7847-
resolved "https://registry.yarnpkg.com/isomorphic-mapzen-search/-/isomorphic-mapzen-search-1.4.1.tgz#914b85d16c23ac0d1e8fb0c90c3ff12503b1c577"
7848-
integrity sha512-5OMaWf3DOU/e2mzU6Q5yCRP9KxMoEX2+tfeZwTWyi3NTKB8pl2nf/dR1XjJ5DpCPlpLWwv8CoBiigeyP7ShmZw==
7845+
isomorphic-mapzen-search@^1.5.1:
7846+
version "1.5.1"
7847+
resolved "https://registry.yarnpkg.com/isomorphic-mapzen-search/-/isomorphic-mapzen-search-1.5.1.tgz#5ac0214cec436fb550e8ef362cf8d11b17de8e9c"
7848+
integrity sha512-38GcjidOqjVQkUzDovx+ceUXHwOliIoFq+qJ/zUzaZwn2h8qEANLMTjaZkFvYN2XdSGB65zBOH5n/iP/Vs1ejA==
78497849
dependencies:
78507850
"@conveyal/lonlat" "^1.1.2"
78517851
isomorphic-fetch "^2.2.1"
@@ -8824,11 +8824,6 @@ lockfile@^1.0.4:
88248824
dependencies:
88258825
signal-exit "^3.0.2"
88268826

8827-
lodash._baseindexof@*:
8828-
version "3.1.0"
8829-
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
8830-
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=
8831-
88328827
lodash._baseuniq@~4.6.0:
88338828
version "4.6.0"
88348829
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
@@ -8837,23 +8832,6 @@ lodash._baseuniq@~4.6.0:
88378832
lodash._createset "~4.0.0"
88388833
lodash._root "~3.0.0"
88398834

8840-
lodash._bindcallback@*:
8841-
version "3.0.1"
8842-
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
8843-
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=
8844-
8845-
lodash._cacheindexof@*:
8846-
version "3.0.2"
8847-
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
8848-
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=
8849-
8850-
lodash._createcache@*:
8851-
version "3.1.2"
8852-
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
8853-
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
8854-
dependencies:
8855-
lodash._getnative "^3.0.0"
8856-
88578835
lodash._createcompounder@^3.0.0:
88588836
version "3.0.0"
88598837
resolved "https://registry.yarnpkg.com/lodash._createcompounder/-/lodash._createcompounder-3.0.0.tgz#5dd2cb55372d6e70e0e2392fb2304d6631091075"
@@ -8867,11 +8845,6 @@ lodash._createset@~4.0.0:
88678845
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
88688846
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=
88698847

8870-
lodash._getnative@*, lodash._getnative@^3.0.0:
8871-
version "3.9.1"
8872-
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
8873-
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=
8874-
88758848
lodash._reinterpolate@^3.0.0:
88768849
version "3.0.0"
88778850
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
@@ -8991,11 +8964,6 @@ lodash.omit@^4.0.1:
89918964
resolved "https://registry.yarnpkg.com/lodash.omit/-/lodash.omit-4.5.0.tgz#6eb19ae5a1ee1dd9df0b969e66ce0b7fa30b5e60"
89928965
integrity sha1-brGa5aHuHdnfC5aeZs4Lf6MLXmA=
89938966

8994-
lodash.restparam@*:
8995-
version "3.6.1"
8996-
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
8997-
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=
8998-
89998967
lodash.set@^4.3.2:
90008968
version "4.3.2"
90018969
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
@@ -10236,7 +10204,6 @@ npm@^6.8.0:
1023610204
cmd-shim "^3.0.3"
1023710205
columnify "~1.5.4"
1023810206
config-chain "^1.1.12"
10239-
debuglog "*"
1024010207
detect-indent "~5.0.0"
1024110208
detect-newline "^2.1.0"
1024210209
dezalgo "~1.0.3"
@@ -10251,7 +10218,6 @@ npm@^6.8.0:
1025110218
has-unicode "~2.0.1"
1025210219
hosted-git-info "^2.8.5"
1025310220
iferr "^1.0.2"
10254-
imurmurhash "*"
1025510221
infer-owner "^1.0.4"
1025610222
inflight "~1.0.6"
1025710223
inherits "^2.0.4"
@@ -10270,14 +10236,8 @@ npm@^6.8.0:
1027010236
libnpx "^10.2.0"
1027110237
lock-verify "^2.1.0"
1027210238
lockfile "^1.0.4"
10273-
lodash._baseindexof "*"
1027410239
lodash._baseuniq "~4.6.0"
10275-
lodash._bindcallback "*"
10276-
lodash._cacheindexof "*"
10277-
lodash._createcache "*"
10278-
lodash._getnative "*"
1027910240
lodash.clonedeep "~4.5.0"
10280-
lodash.restparam "*"
1028110241
lodash.union "~4.6.0"
1028210242
lodash.uniq "~4.5.0"
1028310243
lodash.without "~4.4.0"

0 commit comments

Comments
 (0)