From 4527c8bc9baf557a12b34c0e6a80a4c4efa55704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinto?= Date: Fri, 3 May 2024 20:04:55 +0200 Subject: [PATCH] chore: Update environment variables and API configuration Added specific URLs for the API base URL in each environment and changed the data type of VITE_BYPASS_LOGIN and VITE_BYPASS_TUTORIAL to boolean. Changes made: - Updated VITE_API_BASE_URL with specific URLs for each environment - Changed data type of VITE_BYPASS_LOGIN and VITE_BYPASS_TUTORIAL to boolean - Updated API configuration to ensure security on localhost with the isLocal check - Added comments and descriptions for production and development environments --- .env | 7 +++++-- .env.development | 7 +++++-- src/utils.ts | 5 ++--- vite.env.d.ts | 5 +++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.env b/.env index 86feafaa143..bb76f22b40c 100644 --- a/.env +++ b/.env @@ -1,2 +1,5 @@ -VITE_BYPASS_LOGIN=0 -VITE_BYPASS_TUTORIAL=0 \ No newline at end of file +# Production environment +VITE_ENVIRONMENT="production" +VITE_API_BASE_URL="api" +VITE_BYPASS_LOGIN=false +VITE_BYPASS_TUTORIAL=false \ No newline at end of file diff --git a/.env.development b/.env.development index 88dcdce619c..effc4f15860 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,5 @@ -VITE_BYPASS_LOGIN=1 -VITE_BYPASS_TUTORIAL=0 \ No newline at end of file +# Development environment +VITE_ENVIRONMENT="local" +VITE_API_BASE_URL="http://localhost:8001" +VITE_BYPASS_LOGIN=true +VITE_BYPASS_TUTORIAL=false \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index 577e35c748e..3cae6eb1f2f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -210,9 +210,8 @@ export function executeIf(condition: boolean, promiseFunc: () => Promise): } export const sessionIdKey = 'pokerogue_sessionId'; -export const isLocal = window.location.hostname === 'localhost'; -export const serverUrl = isLocal ? 'http://localhost:8001' : ''; -export const apiUrl = isLocal ? serverUrl : 'api'; +export const isLocal = import.meta.env.VITE_ENVIRONMENT === 'local'; +export const apiUrl = import.meta.env.VITE_API_BASE_URL || (!isLocal ? 'api' : ''); export function setCookie(cName: string, cValue: string): void { const expiration = new Date(); diff --git a/vite.env.d.ts b/vite.env.d.ts index 1bb3a15b588..801785b6384 100644 --- a/vite.env.d.ts +++ b/vite.env.d.ts @@ -1,9 +1,10 @@ /// interface ImportMetaEnv { - readonly VITE_BYPASS_LOGIN: string; - readonly VITE_BYPASS_TUTORIAL: string; + readonly VITE_ENVIRONMENT: string; readonly VITE_API_BASE_URL: string; + readonly VITE_BYPASS_LOGIN: boolean; + readonly VITE_BYPASS_TUTORIAL: boolean; } interface ImportMeta {