1 import { isBrowser } from "./utils";
3 const testHost = "0.0.0.0:8536";
5 function getInternalHost() {
7 ? process.env.LEMMY_UI_LEMMY_INTERNAL_HOST ?? testHost
8 : testHost; // used for local dev
11 export function getExternalHost() {
13 ? `${window.location.hostname}${
14 ["1234", "1235"].includes(window.location.port)
16 : window.location.port == ""
18 : `:${window.location.port}`
20 : process.env.LEMMY_UI_LEMMY_EXTERNAL_HOST || testHost;
23 function getSecure() {
26 ? window.location.protocol.includes("https")
27 : process.env.LEMMY_UI_HTTPS === "true"
34 return isBrowser() ? getExternalHost() : getInternalHost();
37 function getWsHost() {
39 ? window.lemmyConfig?.wsHost ?? getHost()
40 : process.env.LEMMY_UI_LEMMY_WS_HOST ?? getExternalHost();
43 function getBaseLocal(s = "") {
44 return `http${s}://${getHost()}`;
47 export function getHttpBaseInternal() {
48 return getBaseLocal(); // Don't use secure here
50 export function getHttpBase() {
51 return getBaseLocal(getSecure());
53 export function getWsUri() {
54 return `ws${getSecure()}://${getWsHost()}/api/v3/ws`;
56 export function isHttps() {
57 return getSecure() === "s";
60 console.log(`httpbase: ${getHttpBase()}`);
61 console.log(`wsUri: ${getWsUri()}`);
62 console.log(`isHttps: ${isHttps()}`);
64 // This is for html tags, don't include port
65 export function httpExternalPath(path: string) {
66 return `http${getSecure()}://${getExternalHost().replace(