Skip to content

Commit

Permalink
[QoL] Added https and server url is read from the env now (pagefaultg…
Browse files Browse the repository at this point in the history
…ames#1764)

* Added https and server url is read from the env now

* Added the new key to the vite.env.d.ts
  • Loading branch information
CodeTappert authored Jun 7, 2024
1 parent 7c3ace7 commit 97dde2d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
VITE_BYPASS_LOGIN=0
VITE_BYPASS_TUTORIAL=0
VITE_BYPASS_TUTORIAL=0
VITE_SERVER_URL=http://localhost:8001
3 changes: 2 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
VITE_BYPASS_LOGIN=1
VITE_BYPASS_TUTORIAL=0
VITE_BYPASS_TUTORIAL=0
VITE_SERVER_URL=http://localhost:8001
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/vite.env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 97dde2d

Please sign in to comment.