mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-01 18:19:55 +00:00
b19b51c78c
* Add logic for dynamically generating web manifest * Make PWA icon get autogenerated * Make service worker work * Tweak things for PWA * Handle apple icons and refactor * Update prod dockerfile * Remove jimp * Remove unnecessary option * Use different function syntax
70 lines
1.6 KiB
TypeScript
70 lines
1.6 KiB
TypeScript
import { isBrowser } from "./utils";
|
|
|
|
const testHost = "0.0.0.0:8536";
|
|
|
|
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()}`);
|
|
|
|
// This is for html tags, don't include port
|
|
export function httpExternalPath(path: string) {
|
|
return `http${getSecure()}://${getExternalHost().replace(
|
|
/:\d+/g,
|
|
""
|
|
)}${path}`;
|
|
}
|