diff --git a/README.md b/README.md index a9543ff..7afbab8 100644 --- a/README.md +++ b/README.md @@ -17,32 +17,32 @@ See `.env.example` for an example of the required keys and values. ### Visuals -- `PUBLIC_OBA_REGION_NAME` - string: displayed in the header. -- `PUBLIC_OBA_LOGO_URL` - string: The URL of your transit agency's logo. -- `PUBLIC_NAV_BAR_LINKS` - JSON string: A dictionary of the links displayed across the navigation bar. +- `PUBLIC_OBA_REGION_NAME` - string: (required) displayed in the header. +- `PUBLIC_OBA_LOGO_URL` - string: (required) The URL of your transit agency's logo. +- `PUBLIC_NAV_BAR_LINKS` - JSON string: (required) A dictionary of the links displayed across the navigation bar. ### OBA Server -- `PUBLIC_OBA_SERVER_URL` - string: Your OBA API server's URL. -- `PUBLIC_OBA_REGION_CENTER_LAT` - float: The region's center latitude. -- `PUBLIC_OBA_REGION_CENTER_LNG` - float: The region's center longitude. -- `PRIVATE_OBA_API_KEY` - string: Your OneBusAway REST API server key. +- `PUBLIC_OBA_SERVER_URL` - string: (required) Your OBA API server's URL. +- `PUBLIC_OBA_REGION_CENTER_LAT` - float: (required) The region's center latitude. +- `PUBLIC_OBA_REGION_CENTER_LNG` - float: (required) The region's center longitude. +- `PRIVATE_OBA_API_KEY` - string: (required) Your OneBusAway REST API server key. - `PRIVATE_OBACO_API_BASE_URL` - string: (optional) Your OneBusAway.co server base URL, including the path prefix `/api/v1/regions/`. - `PRIVATE_OBACO_SHOW_TEST_ALERTS` - boolean: (optional) Show test alerts on the website. Don't set this value in production. ### Maps -- `PUBLIC_OBA_GOOGLE_MAPS_API_KEY` - string: Your Google API key. Leave this blank if you don't have one. +- `PUBLIC_OBA_GOOGLE_MAPS_API_KEY` - string: (optional) Your Google API key. - `PUBLIC_OBA_MAP_PROVIDER` - string: Use "osm" for OpenStreetMap or "google" for Google Maps. ### Geocoding -- `PRIVATE_OBA_GEOCODER_API_KEY` - string: Your Geocoder service's API key. Ensure that the Geocoder and Places API permissions are enabled. Leave this blank if you don't have one. -- `PRIVATE_OBA_GEOCODER_PROVIDER` - string: Your Geocoder service. We currently only support the Google Places SDK (value: "google"). +- `PRIVATE_OBA_GEOCODER_API_KEY` - string: (optional) Your Geocoder service's API key. Ensure that the Geocoder and Places API permissions are enabled. +- `PRIVATE_OBA_GEOCODER_PROVIDER` - string: (required) Your Geocoder service. We currently only support the Google Places SDK (value: "google"). ### Trip Planner -- `PUBLIC_OTP_SERVER_URL` - string: Your OpenTripPlanner 1.x-compatible trip planner server URL. Leave this blank if you don't have one. +- `PUBLIC_OTP_SERVER_URL` - string: (optional) Your OpenTripPlanner 1.x-compatible trip planner server URL. ## Building diff --git a/src/components/MapContainer.svelte b/src/components/MapContainer.svelte index b0ba9be..29f75ff 100644 --- a/src/components/MapContainer.svelte +++ b/src/components/MapContainer.svelte @@ -4,15 +4,16 @@ import GoogleMapProvider from '$lib/Provider/GoogleMapProvider'; import OpenStreetMapProvider from '$lib/Provider/OpenStreetMapProvider'; import FullPageLoadingSpinner from '$components/FullPageLoadingSpinner.svelte'; - import { - PUBLIC_OBA_MAP_PROVIDER, - PUBLIC_OBA_GOOGLE_MAPS_API_KEY as apiKey - } from '$env/static/public'; + import { env } from '$env/dynamic/public'; + import { PUBLIC_OBA_MAP_PROVIDER } from '$env/static/public'; import { createEventDispatcher, onMount } from 'svelte'; import { MapSource } from './../config/mapSource.js'; export let mapProvider = null; export let mapSource = null; + + let apiKey = env.GOOGLE_MAPS_API_KEY; + const dispatch = createEventDispatcher(); onMount(() => { diff --git a/src/components/search/SearchPane.svelte b/src/components/search/SearchPane.svelte index 5917950..b317afc 100644 --- a/src/components/search/SearchPane.svelte +++ b/src/components/search/SearchPane.svelte @@ -9,7 +9,7 @@ import { clearVehicleMarkersMap, fetchAndUpdateVehicles } from '$lib/vehicleUtils'; import { calculateMidpoint } from '$lib/mathUtils'; import { Tabs, TabItem } from 'flowbite-svelte'; - import { PUBLIC_OTP_SERVER_URL } from '$env/static/public'; + import { env } from '$env/dynamic/public'; import TripPlan from '$components/trip-planner/TripPlan.svelte'; import { isMapLoaded } from '$src/stores/mapStore'; @@ -181,7 +181,7 @@ - {#if PUBLIC_OTP_SERVER_URL} + {#if env.PUBLIC_OTP_SERVER_URL} diff --git a/src/routes/api/oba/alerts/+server.js b/src/routes/api/oba/alerts/+server.js index e17ce08..5334c25 100644 --- a/src/routes/api/oba/alerts/+server.js +++ b/src/routes/api/oba/alerts/+server.js @@ -1,13 +1,13 @@ import GtfsRealtimeBindings from 'gtfs-realtime-bindings'; -import { PRIVATE_OBACO_API_BASE_URL, PRIVATE_OBACO_SHOW_TEST_ALERTS } from '$env/static/private'; +import { env } from '$env/dynamic/private'; import { buildURL } from '$lib/urls.js'; export async function GET() { try { const alertsURL = buildURL( - PRIVATE_OBACO_API_BASE_URL, + env.PRIVATE_OBACO_API_BASE_URL, 'alerts.pb', - PRIVATE_OBACO_SHOW_TEST_ALERTS && PRIVATE_OBACO_SHOW_TEST_ALERTS == 'true' ? { test: 1 } : {} + env.PRIVATE_OBACO_SHOW_TEST_ALERTS == 'true' ? { test: 1 } : {} ); const response = await fetch(alertsURL); @@ -19,7 +19,7 @@ export async function GET() { let validAlert = null; for (const entity of feed.entity) { // If we're in test mode, show the alert to test the UI - if (PRIVATE_OBACO_SHOW_TEST_ALERTS) { + if (env.PRIVATE_OBACO_SHOW_TEST_ALERTS === 'true') { validAlert = entity.alert; break; } diff --git a/src/routes/api/oba/google-geocode-location/+server.js b/src/routes/api/oba/google-geocode-location/+server.js index 27cc05c..9f2c48f 100644 --- a/src/routes/api/oba/google-geocode-location/+server.js +++ b/src/routes/api/oba/google-geocode-location/+server.js @@ -1,9 +1,10 @@ import { googleGeocode } from '$lib/geocoder'; -import { - PRIVATE_OBA_GEOCODER_API_KEY as geocoderApiKey, - PRIVATE_OBA_GEOCODER_PROVIDER as geocoderProvider -} from '$env/static/private'; +import { PRIVATE_OBA_GEOCODER_PROVIDER as geocoderProvider } from '$env/static/private'; + +import { env } from '$env/dynamic/private'; + +let geocoderApiKey = env.PRIVATE_OBA_GEOCODER_API_KEY; async function locationSearch(query) { if (geocoderProvider === 'google') { diff --git a/src/routes/api/oba/google-place-autocomplete/+server.js b/src/routes/api/oba/google-place-autocomplete/+server.js index 8400bea..aca391e 100644 --- a/src/routes/api/oba/google-place-autocomplete/+server.js +++ b/src/routes/api/oba/google-place-autocomplete/+server.js @@ -1,9 +1,10 @@ import { googlePlacesAutocomplete } from '$lib/geocoder'; -import { - PRIVATE_OBA_GEOCODER_API_KEY as geocoderApiKey, - PRIVATE_OBA_GEOCODER_PROVIDER as geocoderProvider -} from '$env/static/private'; +import { PRIVATE_OBA_GEOCODER_PROVIDER as geocoderProvider } from '$env/static/private'; + +import { env } from '$env/dynamic/private'; + +let geocoderApiKey = env.PRIVATE_OBA_GEOCODER_API_KEY; async function autoCompletePlacesSearch(input) { if (geocoderProvider === 'google') { diff --git a/src/routes/api/oba/search/+server.js b/src/routes/api/oba/search/+server.js index 9f67414..d614863 100644 --- a/src/routes/api/oba/search/+server.js +++ b/src/routes/api/oba/search/+server.js @@ -10,10 +10,13 @@ import { import { PRIVATE_OBA_API_KEY as apiKey, - PRIVATE_OBA_GEOCODER_API_KEY as geocoderApiKey, PRIVATE_OBA_GEOCODER_PROVIDER as geocoderProvider } from '$env/static/private'; +import { env } from '$env/dynamic/private'; + +let geocoderApiKey = env.PRIVATE_OBA_GEOCODER_API_KEY; + const oba = new OnebusawaySDK({ apiKey: apiKey, baseURL: baseUrl