Changed How is local is checked and how serverURL is build to prevent… (#1122)

* 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 <bennybroseph@gmail.com>
This commit is contained in:
Jannik Tappert 2024-05-27 17:20:25 +02:00 committed by GitHub
parent 8a6f87cfea
commit f24795d3fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -254,8 +254,14 @@ export function executeIf<T>(condition: boolean, promiseFunc: () => Promise<T>):
} }
export const sessionIdKey = "pokerogue_sessionId"; export const sessionIdKey = "pokerogue_sessionId";
export const isLocal = window.location.hostname === "localhost" || window.location.hostname === ""; // Check if the current hostname is 'localhost' or an IP address, and ensure a port is specified
export const serverUrl = isLocal ? "http://localhost:8001" : ""; 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 const apiUrl = isLocal ? serverUrl : "https://api.pokerogue.net";
export function setCookie(cName: string, cValue: string): void { export function setCookie(cName: string, cValue: string): void {