Skip to content

Commit

Permalink
fix(routerId): persist routerId across sessions
Browse files Browse the repository at this point in the history
fix #161
  • Loading branch information
landonreed committed Jun 22, 2020
1 parent 58e4630 commit 3f68af9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/reducers/create-otp-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ export function getInitialState (userDefinedConfig, initialQuery) {
if (config.locations) {
locations.push(...config.locations.map(l => ({ ...l, type: 'suggested' })))
}
// Check for alternative routerId in session storage. This is generally used
// for testing single GTFS feed OTP graphs that are deployed to feed-specific
// routers (e.g., https://otp.server.com/otp/routers/non_default_router).
// This routerId session value is initially set by visiting otp-rr
// with the path /start/:latLonZoomRouter, which dispatches the SET_ROUTER_ID
// action and stores the value in sessionStorage.
const routerId = window.sessionStorage.getItem('routerId')
if (routerId) {
config.api.path = `/otp/routers/${routerId}`
}
let queryModes = currentQuery.mode.split(',')

// If 'TRANSIT' is included in the mode list, replace it with individual modes
Expand Down Expand Up @@ -541,6 +551,9 @@ function createOtpReducer (config, initialQuery) {
})
case 'SET_ROUTER_ID':
const routerId = action.payload || 'default'
// Store routerId in session storage (persists through page reloads but
// not when a new tab/window is opened).
window.sessionStorage.setItem('routerId', routerId)
return update(state, {
config: {
api: {
Expand Down

0 comments on commit 3f68af9

Please sign in to comment.