summaryrefslogtreecommitdiffhomepage
path: root/frontend/src/utilities/env.ts
blob: f21576a0b05fc4edbe08b2cad4f12a0c41d24354 (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
export const isDevEnv = process.env.NODE_ENV === "development";
export const isProdEnv = process.env.NODE_ENV === "production";
export const isTestEnv = process.env.NODE_ENV === "test";

export const Environment = {
  get apiKey(): string | undefined {
    if (isDevEnv) {
      return process.env["REACT_APP_APIKEY"]!;
    } else if (isTestEnv) {
      return undefined;
    } else {
      return window.Bazarr.apiKey;
    }
  },
  get canUpdate(): boolean {
    if (isDevEnv) {
      return process.env["REACT_APP_CAN_UPDATE"] === "true";
    } else if (isTestEnv) {
      return false;
    } else {
      return window.Bazarr.canUpdate;
    }
  },
  get hasUpdate(): boolean {
    if (isDevEnv) {
      return process.env["REACT_APP_HAS_UPDATE"] === "true";
    } else if (isTestEnv) {
      return false;
    } else {
      return window.Bazarr.hasUpdate;
    }
  },
  get baseUrl(): string {
    if (isDevEnv || isTestEnv) {
      // TODO: Support overriding base URL in development env
      return "";
    } else {
      let url = window.Bazarr.baseUrl;
      if (url.endsWith("/")) {
        url = url.slice(0, -1);
      }
      return url;
    }
  },
  get queryDev(): boolean {
    if (isDevEnv) {
      return process.env["REACT_APP_QUERY_DEV"] === "true";
    }
    return false;
  },
};