[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
This commit is contained in:
Jannik Tappert 2024-06-07 22:43:32 +02:00 committed by GitHub
parent 7c3ace7204
commit 97dde2d1f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 3 deletions

3
.env
View File

@ -1,2 +1,3 @@
VITE_BYPASS_LOGIN=0
VITE_BYPASS_TUTORIAL=0
VITE_BYPASS_TUTORIAL=0
VITE_SERVER_URL=http://localhost:8001

View File

@ -1,2 +1,3 @@
VITE_BYPASS_LOGIN=1
VITE_BYPASS_TUTORIAL=0
VITE_BYPASS_TUTORIAL=0
VITE_SERVER_URL=http://localhost:8001

View File

@ -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;

1
src/vite.env.d.ts vendored
View File

@ -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 {