Skip to content

Commit

Permalink
Merge pull request #124 from OneBusAway/refactor/make-optional-env-va…
Browse files Browse the repository at this point in the history
…rs-dynamic

Refactor/make-optional-env-vars-dynamic
  • Loading branch information
aaronbrethorst authored Nov 15, 2024
2 parents 48814b5 + 31b1a44 commit 10bad4f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<YOUR REGION ID>`.
- `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

Expand Down
9 changes: 5 additions & 4 deletions src/components/MapContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/search/SearchPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -181,7 +181,7 @@
</div>
</TabItem>

{#if PUBLIC_OTP_SERVER_URL}
{#if env.PUBLIC_OTP_SERVER_URL}
<TabItem title="Plan a Trip" on:click={handlePlanTripTabClick} disabled={!mapLoaded}>
<TripPlan {mapProvider} on:tripPlanned={handleTripPlan} />
</TabItem>
Expand Down
8 changes: 4 additions & 4 deletions src/routes/api/oba/alerts/+server.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;
}
Expand Down
9 changes: 5 additions & 4 deletions src/routes/api/oba/google-geocode-location/+server.js
Original file line number Diff line number Diff line change
@@ -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') {
Expand Down
9 changes: 5 additions & 4 deletions src/routes/api/oba/google-place-autocomplete/+server.js
Original file line number Diff line number Diff line change
@@ -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') {
Expand Down
5 changes: 4 additions & 1 deletion src/routes/api/oba/search/+server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 10bad4f

Please sign in to comment.