From 88099fc4c316a2881f9bbb5512070be94abc21b1 Mon Sep 17 00:00:00 2001 From: amalv <1252707+amalv@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:45:34 +0100 Subject: [PATCH] feat: add staging support for API url in apolloClient --- .github/workflows/deploy.yml | 1 + src/apolloClient.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b8c1970..79b3679 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -46,6 +46,7 @@ jobs: VITE_API_URL_PRODUCTION: ${{ secrets.VITE_API_URL_PRODUCTION }} VITE_AUTH0_DOMAIN: ${{ secrets.VITE_AUTH0_DOMAIN }} VITE_AUTH0_CLIENT_ID: ${{ secrets.VITE_AUTH0_CLIENT_ID }} + VITE_ENV: production - name: Setup Pages uses: actions/configure-pages@v4 - name: Upload artifact diff --git a/src/apolloClient.ts b/src/apolloClient.ts index 6bc3c00..48da2fd 100644 --- a/src/apolloClient.ts +++ b/src/apolloClient.ts @@ -10,9 +10,13 @@ export const darkModeVar = makeVar( window?.matchMedia("(prefers-color-scheme: dark)")?.matches ); -const API_URL = - import.meta.env.VITE_API_URL_PRODUCTION || - import.meta.env.VITE_API_URL_DEVELOPMENT; +const apiUrlMap = { + production: import.meta.env.VITE_API_URL_PRODUCTION, + staging: import.meta.env.VITE_API_URL_STAGING, + development: import.meta.env.VITE_API_URL_DEVELOPMENT, +}; + +const API_URL = apiUrlMap[import.meta.env.VITE_ENV] || apiUrlMap.development; const httpLink = createHttpLink({ uri: API_URL,