2023-06-16 21:25:53 +00:00
|
|
|
import { isBrowser } from "./utils/browser/is-browser";
|
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 getBaseLocal(s = "") {
|
|
|
|
return `http${s}://${getHost()}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getHttpBaseInternal() {
|
|
|
|
return getBaseLocal(); // Don't use secure here
|
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
|
|
|
|
export function getHttpBaseExternal() {
|
|
|
|
return `http${getSecure()}://${getExternalHost()}`;
|
|
|
|
}
|
|
|
|
|
2023-05-12 01:07:59 +00:00
|
|
|
export function getHttpBase() {
|
|
|
|
return getBaseLocal(getSecure());
|
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
|
2023-05-12 01:07:59 +00:00
|
|
|
export function isHttps() {
|
|
|
|
return getSecure() === "s";
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`httpbase: ${getHttpBase()}`);
|
|
|
|
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
|
|
|
}
|