Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load POIS from file #29

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading