Skip to content

Commit

Permalink
Merge pull request #29 from ibi-group/load-pois-from-file
Browse files Browse the repository at this point in the history
Load POIS from file
  • Loading branch information
miles-grant-ibigroup authored Apr 16, 2024
2 parents 4623ba9 + 73a8677 commit b0f3581
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ dist
.DS_Store

# Secrets
env.yml
env.yml
pois.json
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b0f3581

Please sign in to comment.