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. diff --git a/handler.ts b/handler.ts index 21ae889..100d1b3 100644 --- a/handler.ts +++ b/handler.ts @@ -23,7 +23,9 @@ 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,7 +37,7 @@ 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) => { + ? (POIS as OfflineResponse).map((poi) => { if (typeof poi.lat === 'string') { poi.lat = parseFloat(poi.lat) } 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: