2021-02-22 02:39:04 +00:00
|
|
|
import { isBrowser } from "./utils";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2022-05-06 03:12:42 +00:00
|
|
|
const testHost = "0.0.0.0:8536";
|
2020-09-11 18:09:21 +00:00
|
|
|
|
2021-02-12 17:54:35 +00:00
|
|
|
let internalHost =
|
2020-10-24 17:12:13 +00:00
|
|
|
(!isBrowser() && process.env.LEMMY_INTERNAL_HOST) || testHost; // used for local dev
|
2021-02-12 17:54:35 +00:00
|
|
|
export let externalHost: string;
|
|
|
|
let host: string;
|
|
|
|
let wsHost: string;
|
|
|
|
let secure: string;
|
|
|
|
|
|
|
|
if (isBrowser()) {
|
|
|
|
// browser
|
|
|
|
const lemmyConfig =
|
2021-02-22 02:39:04 +00:00
|
|
|
typeof window.lemmyConfig !== "undefined" ? window.lemmyConfig : {};
|
2021-02-12 17:54:35 +00:00
|
|
|
|
|
|
|
externalHost = `${window.location.hostname}${
|
2021-02-22 02:39:04 +00:00
|
|
|
["1234", "1235"].includes(window.location.port)
|
|
|
|
? ":8536"
|
|
|
|
: window.location.port == ""
|
|
|
|
? ""
|
2021-02-12 17:54:35 +00:00
|
|
|
: `:${window.location.port}`
|
|
|
|
}`;
|
|
|
|
|
|
|
|
host = externalHost;
|
|
|
|
wsHost = lemmyConfig.wsHost || host;
|
2021-02-22 02:39:04 +00:00
|
|
|
secure = window.location.protocol == "https:" ? "s" : "";
|
2021-02-12 17:54:35 +00:00
|
|
|
} else {
|
|
|
|
// server-side
|
|
|
|
externalHost = process.env.LEMMY_EXTERNAL_HOST || testHost;
|
|
|
|
host = internalHost;
|
2022-06-01 16:43:54 +00:00
|
|
|
wsHost = process.env.LEMMY_WS_HOST || externalHost;
|
2021-02-22 02:39:04 +00:00
|
|
|
secure = process.env.LEMMY_HTTPS == "true" ? "s" : "";
|
2021-02-12 17:54:35 +00:00
|
|
|
}
|
2020-09-11 18:09:21 +00:00
|
|
|
|
2021-04-26 19:32:59 +00:00
|
|
|
export const httpBaseInternal = `http://${host}`; // Don't use secure here
|
|
|
|
export const httpBase = `http${secure}://${host}`;
|
2022-05-06 03:12:42 +00:00
|
|
|
export const wsUriBase = `ws${secure}://${wsHost}`;
|
|
|
|
export const wsUri = `${wsUriBase}/api/v3/ws`;
|
2021-04-26 19:32:59 +00:00
|
|
|
export const pictrsUri = `${httpBase}/pictrs/image`;
|
2021-09-18 21:59:28 +00:00
|
|
|
export const isHttps = secure.endsWith("s");
|
2020-09-11 18:09:21 +00:00
|
|
|
|
2020-09-15 15:55:38 +00:00
|
|
|
console.log(`httpbase: ${httpBase}`);
|
|
|
|
console.log(`wsUri: ${wsUri}`);
|
2021-09-18 21:59:28 +00:00
|
|
|
console.log(`isHttps: ${isHttps}`);
|
2020-09-15 15:55:38 +00:00
|
|
|
|
2020-09-12 02:37:27 +00:00
|
|
|
// This is for html tags, don't include port
|
2021-02-22 02:39:04 +00:00
|
|
|
const httpExternalUri = `http${secure}://${externalHost.split(":")[0]}`;
|
2020-09-11 18:09:21 +00:00
|
|
|
export function httpExternalPath(path: string) {
|
|
|
|
return `${httpExternalUri}${path}`;
|
|
|
|
}
|