Skip to content

Commit

Permalink
add POI support using otp-ui offline geocoder
Browse files Browse the repository at this point in the history
  • Loading branch information
miles-grant-ibigroup committed Feb 27, 2024
1 parent 8564364 commit b54c97f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const {
REDIS_HOST,
REDIS_KEY,
GEOCODERS,

Check failure on line 30 in handler.ts

View workflow job for this annotation

GitHub Actions / test-lambda-function

Expected object keys to be in sorted order. Expected GEOCODERS to be before REDIS_KEY
POIS,
BACKUP_GEOCODERS
} = process.env

Expand All @@ -53,6 +54,8 @@ if (!GEOCODERS) {
}
const geocoders = JSON.parse(GEOCODERS)
const backupGeocoders = BACKUP_GEOCODERS && JSON.parse(BACKUP_GEOCODERS)
// Serverless is not great about null
const pois = POIS && POIS !== "null" ? JSON.parse(POIS) : []

Check failure on line 58 in handler.ts

View workflow job for this annotation

GitHub Actions / test-lambda-function

Replace `"null"` with `'null'`

if (geocoders.length !== backupGeocoders.length) {
throw new Error('Error: BACKUP_GEOCODERS is not set to the same length as GEOCODERS')
Expand All @@ -68,7 +71,6 @@ Bugsnag.start({
// This handler will wrap around the handler code
// and will report exceptions to Bugsnag automatically.
// For reference, see https://docs.bugsnag.com/platforms/javascript/aws-lambda/#usage
// @ts-expect-error bugsnag plugin has weird types
const bugsnagHandler = Bugsnag.getPlugin('awsLambda').createHandler()

/**
Expand Down Expand Up @@ -98,7 +100,7 @@ export const makeGeocoderRequests = async (

// Run both requests in parallel
let responses: FeatureCollection[] = await Promise.all(geocoders.map(geocoder => cachedGeocoderRequest(
getGeocoder(geocoder), apiMethod, convertQSPToGeocoderArgs(event.queryStringParameters),
getGeocoder(geocoder), apiMethod, { ...convertQSPToGeocoderArgs(event.queryStringParameters), items: pois },
// TODO: add redis here
null

Expand All @@ -117,6 +119,7 @@ export const makeGeocoderRequests = async (

const merged = responses.reduce((prev, cur, idx) => {

Check warning on line 120 in handler.ts

View workflow job for this annotation

GitHub Actions / test-lambda-function

Array.prototype.reduce() expects a value to be returned at the end of arrow function
if (idx === 0) return cur
// @ts-expect-error Typechecking is broken here for some reason
if (prev) return mergeResponses({ primaryResponse: prev, customResponse: cur })

Check warning on line 123 in handler.ts

View workflow job for this annotation

GitHub Actions / test-lambda-function

Expected object keys to be in ascending order. 'customResponse' should be before 'primaryResponse'
}, null)

Expand Down
1 change: 1 addition & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ provider:
environment:
GEOCODERS: ${self:custom.secrets.GEOCODERS}
BACKUP_GEOCODERS: ${self:custom.secrets.BACKUP_GEOCODERS}
POIS: ${self:custom.secrets.POIS, null}
BUGSNAG_NOTIFIER_KEY: ${self:custom.secrets.BUGSNAG_NOTIFIER_KEY}
REDIS_HOST: ${self:custom.secrets.REDIS_HOST, null}
REDIS_KEY: ${self:custom.secrets.REDIS_KEY, null}
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2222,6 +2222,11 @@
resolved "https://registry.yarnpkg.com/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz#8ace5259254426ccef57f3175bc64ed7095ed919"
integrity sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==

"@leeoniya/ufuzzy@^1.0.14":
version "1.0.14"
resolved "https://registry.yarnpkg.com/@leeoniya/ufuzzy/-/ufuzzy-1.0.14.tgz#01572c0de9cfa1420cf6ecac76dd59db5ebd1337"
integrity sha512-/xF4baYuCQMo+L/fMSUrZnibcu0BquEGnbxfVPiZhs/NbJeKj4c/UmFpQzW9Us0w45ui/yYW3vyaqawhNYsTzA==

"@mrmlnc/readdir-enhanced@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde"
Expand Down

0 comments on commit b54c97f

Please sign in to comment.