From 42103cd603e485148413dc0ed66c7ffa64b8134c Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Tue, 26 Oct 2021 14:40:50 +0100 Subject: [PATCH] feat(actions/api): route only flex requests to otp2 server --- example-config.yml | 7 +++++++ lib/actions/api.js | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/example-config.yml b/example-config.yml index 6d302511b..553b77ef0 100644 --- a/example-config.yml +++ b/example-config.yml @@ -2,6 +2,13 @@ api: host: http://localhost path: /otp/routers/default port: 8001 + +# Support OTP-2 in parallel for certain requests +# api_v2: +# host: http://localhost +# path: /otp/routers/default +# port: 8002 + # Add suggested locations to be shown as options in the form view. # locations: # - id: 'airport' diff --git a/lib/actions/api.js b/lib/actions/api.js index c79cbb6cf..ab78e61b0 100644 --- a/lib/actions/api.js +++ b/lib/actions/api.js @@ -252,9 +252,15 @@ function getOtpFetchOptions (state, includeToken = false) { function constructRoutingQuery (state, ignoreRealtimeUpdates, injectedParams = {}) { const { config, currentQuery } = state.otp const routingType = currentQuery.routingType + const routingMode = injectedParams?.mode || currentQuery.mode + // Check for routingType-specific API config; if none, use default API const rt = config.routingTypes && config.routingTypes.find(rt => rt.key === routingType) - const api = (rt && rt.api) || config.api + + // Certain requests will require OTP-2. If an OTP-2 host is specified, set it to be used + const useOtp2 = !!config.api_v2 && routingMode.includes('FLEX') + + const api = (rt && rt.api) || (useOtp2 && config.api_v2) || config.api const planEndpoint = `${api.host}${api.port ? ':' + api.port : ''}${api.path}/plan`