-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathenv.ts
25 lines (22 loc) · 1010 Bytes
/
env.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
export const PROJECT_NAME = process.env.REACT_APP_PROJECT_NAME || 'ESP8266 React';
export const PROJECT_PATH = process.env.REACT_APP_PROJECT_PATH || 'project';
export const ENDPOINT_ROOT = calculateEndpointRoot("/rest/");
export const EVENT_SOURCE_ROOT = calculateEndpointRoot("/es/");
export const WEB_SOCKET_ROOT = calculateWebSocketRoot("/ws/");
function calculateEndpointRoot(endpointPath: string) {
const httpRoot = process.env.REACT_APP_HTTP_ROOT;
if (httpRoot) {
return httpRoot + endpointPath;
}
const location = window.location;
return location.protocol + "//" + location.host + endpointPath;
}
function calculateWebSocketRoot(webSocketPath: string) {
const webSocketRoot = process.env.REACT_APP_WEB_SOCKET_ROOT;
if (webSocketRoot) {
return webSocketRoot + webSocketPath;
}
const location = window.location;
const webProtocol = location.protocol === "https:" ? "wss:" : "ws:";
return webProtocol + "//" + location.host + webSocketPath;
}