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
|
|
|
|
2023-05-12 01:07:59 +00:00
|
|
|
function getInternalHost() {
|
|
|
|
return !isBrowser()
|
|
|
|
? process.env.LEMMY_UI_LEMMY_INTERNAL_HOST ?? testHost
|
|
|
|
: testHost; // used for local dev
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getExternalHost() {
|
|
|
|
return isBrowser()
|
|
|
|
? `${window.location.hostname}${
|
|
|
|
["1234", "1235"].includes(window.location.port)
|
|
|
|
? ":8536"
|
|
|
|
: window.location.port == ""
|
|
|
|
? ""
|
|
|
|
: `:${window.location.port}`
|
|
|
|
}`
|
|
|
|
: process.env.LEMMY_UI_LEMMY_EXTERNAL_HOST || testHost;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSecure() {
|
|
|
|
return (
|
|
|
|
isBrowser()
|
|
|
|
? window.location.protocol.includes("https")
|
|
|
|
: process.env.LEMMY_UI_HTTPS === "true"
|
|
|
|
)
|
|
|
|
? "s"
|
|
|
|
: "";
|
|
|
|
}
|
|
|
|
|
|
|
|
function getHost() {
|
|
|
|
return isBrowser() ? getExternalHost() : getInternalHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getWsHost() {
|
|
|
|
return isBrowser()
|
|
|
|
? window.lemmyConfig?.wsHost ?? getHost()
|
|
|
|
: process.env.LEMMY_UI_LEMMY_WS_HOST ?? getExternalHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBaseLocal(s = "") {
|
|
|
|
return `http${s}://${getHost()}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getHttpBaseInternal() {
|
|
|
|
return getBaseLocal(); // Don't use secure here
|
|
|
|
}
|
|
|
|
export function getHttpBase() {
|
|
|
|
return getBaseLocal(getSecure());
|
|
|
|
}
|
|
|
|
export function getWsUri() {
|
|
|
|
return `ws${getSecure()}://${getWsHost()}/api/v3/ws`;
|
|
|
|
}
|
|
|
|
export function isHttps() {
|
|
|
|
return getSecure() === "s";
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`httpbase: ${getHttpBase()}`);
|
|
|
|
console.log(`wsUri: ${getWsUri()}`);
|
|
|
|
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
|
2020-09-11 18:09:21 +00:00
|
|
|
export function httpExternalPath(path: string) {
|
2023-05-12 01:07:59 +00:00
|
|
|
return `http${getSecure()}://${getExternalHost().replace(
|
|
|
|
/:\d+/g,
|
|
|
|
""
|
|
|
|
)}${path}`;
|
2020-09-11 18:09:21 +00:00
|
|
|
}
|