From b13c0f9302d1dd7c35e28344f321f7af70e868e0 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Fri, 12 Apr 2024 16:25:36 -0400 Subject: [PATCH 1/3] fix: load pois from file --- handler.ts | 21 +++++++++++---------- serverless.yml | 4 +++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/handler.ts b/handler.ts index 21ae889..6632965 100644 --- a/handler.ts +++ b/handler.ts @@ -23,7 +23,8 @@ import { // This plugin must be imported via cjs to ensure its existence (typescript recommendation) const BugsnagPluginAwsLambda = require('@bugsnag/plugin-aws-lambda') -const { BACKUP_GEOCODERS, BUGSNAG_NOTIFIER_KEY, GEOCODERS, POIS } = process.env +const { BACKUP_GEOCODERS, BUGSNAG_NOTIFIER_KEY, GEOCODERS } = process.env +const POIS = require('./pois.json') if (!GEOCODERS) { throw new Error( @@ -35,15 +36,15 @@ const backupGeocoders = BACKUP_GEOCODERS && JSON.parse(BACKUP_GEOCODERS) // Serverless is not great about null const pois = POIS && POIS !== 'null' - ? (JSON.parse(POIS) as OfflineResponse).map((poi) => { - if (typeof poi.lat === 'string') { - poi.lat = parseFloat(poi.lat) - } - if (typeof poi.lon === 'string') { - poi.lon = parseFloat(poi.lon) - } - return poi - }) + ? (POIS as OfflineResponse).map((poi) => { + if (typeof poi.lat === 'string') { + poi.lat = parseFloat(poi.lat) + } + if (typeof poi.lon === 'string') { + poi.lon = parseFloat(poi.lon) + } + return poi + }) : [] if (geocoders.length !== backupGeocoders.length) { diff --git a/serverless.yml b/serverless.yml index 4e1c80c..d34b179 100644 --- a/serverless.yml +++ b/serverless.yml @@ -11,8 +11,10 @@ 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} +package: + patterns: + - pois.json custom: secrets: ${file(env.yml)} functions: From d67fe89c1f0b3d2a6e6ca7b910ef3db44e2718c8 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Fri, 12 Apr 2024 16:33:53 -0400 Subject: [PATCH 2/3] update readme to talk about `pois.json` --- .gitignore | 3 ++- README.md | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7ca47bd..a9489ab 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ dist .DS_Store # Secrets -env.yml \ No newline at end of file +env.yml +pois.json diff --git a/README.md b/README.md index d63d463..617701d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This folder contains an AWS lambda script which pretends to be a Pelias endpoint. It will forward any request it receives to both Geocode.earth (using the API key in `env.yml`) and a custom Pelias instance (defined in `env.yml`). It will merge the responses together seamlessly. The client will think it's communicating only with a regular Pelias server. +If you enable the offline geocoder, POIs are loaded in through `pois.json` in the root directory. The format is a raw array `[]`. + ## Running Locally Local running is done via the offline serverless plugin. The plugin will automatically build the TypeScript and start a server. Create an `env.yml` file based on the example file provided. From 73a8677bd1a8ea17b6369ecfcc213dcca0dec768 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Fri, 12 Apr 2024 16:38:16 -0400 Subject: [PATCH 3/3] chore: lint --- handler.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/handler.ts b/handler.ts index 6632965..100d1b3 100644 --- a/handler.ts +++ b/handler.ts @@ -23,6 +23,7 @@ import { // This plugin must be imported via cjs to ensure its existence (typescript recommendation) const BugsnagPluginAwsLambda = require('@bugsnag/plugin-aws-lambda') + const { BACKUP_GEOCODERS, BUGSNAG_NOTIFIER_KEY, GEOCODERS } = process.env const POIS = require('./pois.json') @@ -37,14 +38,14 @@ const backupGeocoders = BACKUP_GEOCODERS && JSON.parse(BACKUP_GEOCODERS) const pois = POIS && POIS !== 'null' ? (POIS as OfflineResponse).map((poi) => { - if (typeof poi.lat === 'string') { - poi.lat = parseFloat(poi.lat) - } - if (typeof poi.lon === 'string') { - poi.lon = parseFloat(poi.lon) - } - return poi - }) + if (typeof poi.lat === 'string') { + poi.lat = parseFloat(poi.lat) + } + if (typeof poi.lon === 'string') { + poi.lon = parseFloat(poi.lon) + } + return poi + }) : [] if (geocoders.length !== backupGeocoders.length) {