-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
// settings.ts | ||
|
||
export const isClient = typeof window !== 'undefined'; | ||
export const isClient = typeof window !== "undefined"; | ||
|
||
export const isDev = process.env.NODE_ENV === 'development'; | ||
export const isDev = process.env.NODE_ENV === "development"; | ||
|
||
const loadConfig = () => { | ||
const request = new XMLHttpRequest(); | ||
request.open('GET', '/config.json', false); // Synchronous request | ||
request.send(null); | ||
const request = new XMLHttpRequest(); | ||
request.open("GET", "/config.json", false); // Synchronous request | ||
request.send(null); | ||
|
||
if (request.status === 200) { | ||
return JSON.parse(request.responseText); | ||
} else { | ||
throw new Error(`Failed to load config: ${request.status}`); | ||
} | ||
if (request.status === 200) { | ||
return JSON.parse(request.responseText); | ||
} else { | ||
throw new Error(`Failed to load config: ${request.status}`); | ||
} | ||
}; | ||
|
||
const config = loadConfig(); | ||
|
||
export const defaultPort = config.defaultPort; | ||
export const defaultBaseUrl = config.defaultBaseUrl; | ||
|
||
export const baseHostURL = isClient && !isDev ? `${window.location.protocol}//${window.location.host}` : `http://127.0.0.1:${defaultPort}${defaultBaseUrl}`; | ||
export const baseHostURL = | ||
isClient && !isDev | ||
? `${window.location.protocol}//${window.location.host}` | ||
: `http://localhost:${defaultPort}${defaultBaseUrl}`; |