From 97dde2d1f39ba835eef5279ad3a2808598163c95 Mon Sep 17 00:00:00 2001 From: Jannik Tappert <38758606+CodeTappert@users.noreply.github.com> Date: Fri, 7 Jun 2024 22:43:32 +0200 Subject: [PATCH] [QoL] Added https and server url is read from the env now (#1764) * Added https and server url is read from the env now * Added the new key to the vite.env.d.ts --- .env | 3 ++- .env.development | 3 ++- src/utils.ts | 4 +++- src/vite.env.d.ts | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 86feafaa143..6ac42ba97b4 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ VITE_BYPASS_LOGIN=0 -VITE_BYPASS_TUTORIAL=0 \ No newline at end of file +VITE_BYPASS_TUTORIAL=0 +VITE_SERVER_URL=http://localhost:8001 \ No newline at end of file diff --git a/.env.development b/.env.development index 88dcdce619c..e9180f0875d 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,3 @@ VITE_BYPASS_LOGIN=1 -VITE_BYPASS_TUTORIAL=0 \ No newline at end of file +VITE_BYPASS_TUTORIAL=0 +VITE_SERVER_URL=http://localhost:8001 \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index 42736add1fa..7b25c4990e1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -277,8 +277,10 @@ export const isLocal = ( /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/.test(window.location.hostname)) && window.location.port !== "") || window.location.hostname === ""; +export const localServerUrl = import.meta.env.VITE_SERVER_URL ?? `http://${window.location.hostname}:${window.location.port+1}`; + // Set the server URL based on whether it's local or not -export const serverUrl = isLocal ? `${window.location.hostname}:${window.location.port}` : ""; +export const serverUrl = isLocal ? localServerUrl : ""; export const apiUrl = isLocal ? serverUrl : "https://api.pokerogue.net"; // used to disable api calls when isLocal is true and a server is not found export let isLocalServerConnected = false; diff --git a/src/vite.env.d.ts b/src/vite.env.d.ts index 50bb7dddc02..b588b5b1145 100644 --- a/src/vite.env.d.ts +++ b/src/vite.env.d.ts @@ -4,6 +4,7 @@ interface ImportMetaEnv { readonly VITE_BYPASS_LOGIN?: string; readonly VITE_BYPASS_TUTORIAL?: string; readonly VITE_API_BASE_URL?: string; + readonly VITE_SERVER_URL?: string; } interface ImportMeta {