From c24280cc574ff9509fc4c171408abe86728db0fa Mon Sep 17 00:00:00 2001 From: Nathan Franklin Date: Wed, 12 Feb 2025 00:51:18 +0100 Subject: [PATCH] Hotfix/allow user to set which DesignSafe site to use in local dev (#318) * Allow user to set which DS site to use during local development * Update example * Improve comment --- .../environment/getLocalAppConfiguration.ts | 23 ++++++++++++++++--- react/src/secret_local.example.ts | 9 ++++++-- react/src/types/environment.ts | 3 +++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/react/src/hooks/environment/getLocalAppConfiguration.ts b/react/src/hooks/environment/getLocalAppConfiguration.ts index 1aeeb102..17a8df80 100644 --- a/react/src/hooks/environment/getLocalAppConfiguration.ts +++ b/react/src/hooks/environment/getLocalAppConfiguration.ts @@ -5,6 +5,7 @@ import { AppConfiguration, MapillaryConfiguration, DesignSafePortalEnvironment, + GeoapiBackendEnvironment, } from '@hazmapper/types'; /** @@ -16,12 +17,27 @@ export const getLocalAppConfiguration = ( basePath: string, mapillaryConfig: MapillaryConfiguration ): AppConfiguration => { + const designSafePortal = + localDevelopmentConfiguration.designSafePortal ?? + DesignSafePortalEnvironment.PPRD; + + // Check for possible mismatches in Geoapi production or Geoapi staging, as these deployed environments correspond to DS prod and pprd, respectively. + if ( + (localDevelopmentConfiguration.geoapiBackend === + GeoapiBackendEnvironment.Production && + designSafePortal !== DesignSafePortalEnvironment.Production) || + (localDevelopmentConfiguration.geoapiBackend === + GeoapiBackendEnvironment.Staging && + designSafePortal !== DesignSafePortalEnvironment.PPRD) + ) { + const msg = `Mismatch detected: geoapiBackend is '${localDevelopmentConfiguration.geoapiBackend}', but designSafePortal is '${designSafePortal}'.`; + throw new Error(msg); + } + const appConfig: AppConfiguration = { basePath: basePath, geoapiUrl: getGeoapiUrl(localDevelopmentConfiguration.geoapiBackend), - designsafePortalUrl: getDesignsafePortalUrl( - DesignSafePortalEnvironment.PPRD - ), + designsafePortalUrl: getDesignsafePortalUrl(designSafePortal), tapisUrl: 'https://designsafe.tapis.io', mapillary: mapillaryConfig, taggitUrl: origin + '/taggit-staging', @@ -31,5 +47,6 @@ export const getLocalAppConfiguration = ( 'MLY|5156692464392931|6be48c9f4074f4d486e0c42a012b349f'; appConfig.mapillary.clientToken = 'MLY|5156692464392931|4f1118aa1b06f051a44217cb56bedf79'; + return appConfig; }; diff --git a/react/src/secret_local.example.ts b/react/src/secret_local.example.ts index ae7e1816..9eed807d 100644 --- a/react/src/secret_local.example.ts +++ b/react/src/secret_local.example.ts @@ -1,5 +1,10 @@ -import { GeoapiBackendEnvironment, LocalAppConfiguration } from './types'; +import { + DesignSafePortalEnvironment, + GeoapiBackendEnvironment, + LocalAppConfiguration, +} from './types'; export const localDevelopmentConfiguration: LocalAppConfiguration = { - geoapiBackend: GeoapiBackendEnvironment.Production, + geoapiBackend: GeoapiBackendEnvironment.Staging, + designSafePortal: DesignSafePortalEnvironment.PPRD, }; diff --git a/react/src/types/environment.ts b/react/src/types/environment.ts index fb48f3bd..fb12d0c4 100644 --- a/react/src/types/environment.ts +++ b/react/src/types/environment.ts @@ -45,6 +45,9 @@ export enum ApiService { export interface LocalAppConfiguration { /* The type of backend environment (production, staging, development, or local) */ geoapiBackend: GeoapiBackendEnvironment; + + /** Type of GeoAPI service. Defaults to PPRD if not provided */ + designSafePortal?: DesignSafePortalEnvironment; } /**