From f24795d3fc41f550ad22592d5cc856860ae6be34 Mon Sep 17 00:00:00 2001 From: Jannik Tappert <38758606+CodeTappert@users.noreply.github.com> Date: Mon, 27 May 2024 17:20:25 +0200 Subject: [PATCH] =?UTF-8?q?Changed=20How=20is=20local=20is=20checked=20and?= =?UTF-8?q?=20how=20serverURL=20is=20build=20to=20prevent=E2=80=A6=20(#112?= =?UTF-8?q?2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Changed How is local is checked and how serverURL is build to prevent errros in offline mode * Added window.location.hostname === ''; back as a check * Removed any line breaks in the isLocal Condition * 3rd time is the charme * Update utils.ts --------- Co-authored-by: Benjamin Odom --- src/utils.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index faf3d8f54bf..cfdbfc2a942 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -254,8 +254,14 @@ export function executeIf(condition: boolean, promiseFunc: () => Promise): } export const sessionIdKey = "pokerogue_sessionId"; -export const isLocal = window.location.hostname === "localhost" || window.location.hostname === ""; -export const serverUrl = isLocal ? "http://localhost:8001" : ""; +// Check if the current hostname is 'localhost' or an IP address, and ensure a port is specified +export const isLocal = ( + (window.location.hostname === "localhost" || + /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/.test(window.location.hostname)) && + window.location.port !== "") || window.location.hostname === ""; + +// Set the server URL based on whether it's local or not +export const serverUrl = isLocal ? `${window.location.hostname}:${window.location.port}` : ""; export const apiUrl = isLocal ? serverUrl : "https://api.pokerogue.net"; export function setCookie(cName: string, cValue: string): void {