]> Untitled Git - lemmy-ui.git/blob - src/shared/env.ts
Change from using Link to NavLink. resolve #269
[lemmy-ui.git] / src / shared / env.ts
1 import { isBrowser } from "./utils";
2
3 const testHost = "localhost:8536";
4
5 let internalHost =
6   (!isBrowser() && process.env.LEMMY_INTERNAL_HOST) || testHost; // used for local dev
7 export let externalHost: string;
8 let host: string;
9 let wsHost: string;
10 let secure: string;
11
12 if (isBrowser()) {
13   // browser
14   const lemmyConfig =
15     typeof window.lemmyConfig !== "undefined" ? window.lemmyConfig : {};
16
17   externalHost = `${window.location.hostname}${
18     ["1234", "1235"].includes(window.location.port)
19       ? ":8536"
20       : window.location.port == ""
21       ? ""
22       : `:${window.location.port}`
23   }`;
24
25   host = externalHost;
26   wsHost = lemmyConfig.wsHost || host;
27   secure = window.location.protocol == "https:" ? "s" : "";
28 } else {
29   // server-side
30   externalHost = process.env.LEMMY_EXTERNAL_HOST || testHost;
31   host = internalHost;
32   wsHost = process.env.LEMMY_WS_HOST || host;
33   secure = process.env.LEMMY_HTTPS == "true" ? "s" : "";
34 }
35
36 export const httpBase = `http://${host}`; // Don't use secure here
37 export const wsUri = `ws${secure}://${wsHost}/api/v3/ws`;
38 export const pictrsUri = `http${secure}://${host}/pictrs/image`;
39
40 console.log(`httpbase: ${httpBase}`);
41 console.log(`wsUri: ${wsUri}`);
42
43 // This is for html tags, don't include port
44 const httpExternalUri = `http${secure}://${externalHost.split(":")[0]}`;
45 export function httpExternalPath(path: string) {
46   return `${httpExternalUri}${path}`;
47 }