mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-26 14:21:13 +00:00
move env utils into folder
This commit is contained in:
parent
cda9bd0a79
commit
fc40b473d7
20 changed files with 105 additions and 73 deletions
|
@ -1,4 +1,5 @@
|
||||||
import { initializeSite, isAuthPath } from "@utils/app";
|
import { initializeSite, isAuthPath } from "@utils/app";
|
||||||
|
import { getHttpBaseInternal } from "@utils/env";
|
||||||
import { ErrorPageData } from "@utils/types";
|
import { ErrorPageData } from "@utils/types";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { StaticRouter, matchPath } from "inferno-router";
|
import { StaticRouter, matchPath } from "inferno-router";
|
||||||
|
@ -6,7 +7,6 @@ import { renderToString } from "inferno-server";
|
||||||
import IsomorphicCookie from "isomorphic-cookie";
|
import IsomorphicCookie from "isomorphic-cookie";
|
||||||
import { GetSite, GetSiteResponse, LemmyHttp } from "lemmy-js-client";
|
import { GetSite, GetSiteResponse, LemmyHttp } from "lemmy-js-client";
|
||||||
import { App } from "../../shared/components/app/app";
|
import { App } from "../../shared/components/app/app";
|
||||||
import { getHttpBaseInternal } from "../../shared/env";
|
|
||||||
import {
|
import {
|
||||||
InitialFetchRequest,
|
InitialFetchRequest,
|
||||||
IsoDataOptionalSite,
|
IsoDataOptionalSite,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
import { getHttpBaseExternal, getHttpBaseInternal } from "@utils/env";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { LemmyHttp } from "lemmy-js-client";
|
import { LemmyHttp } from "lemmy-js-client";
|
||||||
import { getHttpBaseExternal, getHttpBaseInternal } from "../../shared/env";
|
|
||||||
import { wrapClient } from "../../shared/services/HttpService";
|
import { wrapClient } from "../../shared/services/HttpService";
|
||||||
import generateManifestJson from "../utils/generate-manifest-json";
|
import generateManifestJson from "../utils/generate-manifest-json";
|
||||||
import { setForwardedHeaders } from "../utils/set-forwarded-headers";
|
import { setForwardedHeaders } from "../utils/set-forwarded-headers";
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
import { getHttpBaseExternal } from "@utils/env";
|
||||||
import { readFile } from "fs/promises";
|
import { readFile } from "fs/promises";
|
||||||
import { GetSiteResponse } from "lemmy-js-client";
|
import { GetSiteResponse } from "lemmy-js-client";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
import { getHttpBaseExternal } from "../../shared/env";
|
|
||||||
import { fetchIconPng } from "./fetch-icon-png";
|
import { fetchIconPng } from "./fetch-icon-png";
|
||||||
|
|
||||||
const iconSizes = [72, 96, 128, 144, 152, 192, 384, 512];
|
const iconSizes = [72, 96, 128, 144, 152, 192, 384, 512];
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
import { httpExternalPath } from "@utils/env";
|
||||||
import { htmlToText } from "html-to-text";
|
import { htmlToText } from "html-to-text";
|
||||||
import { Component } from "inferno";
|
import { Component } from "inferno";
|
||||||
import { Helmet } from "inferno-helmet";
|
import { Helmet } from "inferno-helmet";
|
||||||
import { httpExternalPath } from "../../env";
|
|
||||||
import { md } from "../../markdown";
|
import { md } from "../../markdown";
|
||||||
import { I18NextService } from "../../services";
|
import { I18NextService } from "../../services";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { myAuthRequired, newVote, showScores } from "@utils/app";
|
import { myAuthRequired, newVote, showScores } from "@utils/app";
|
||||||
import { canShare, share } from "@utils/browser";
|
import { canShare, share } from "@utils/browser";
|
||||||
|
import { getExternalHost, getHttpBase } from "@utils/env";
|
||||||
import { futureDaysToUnixTime, hostname, numToSI } from "@utils/helpers";
|
import { futureDaysToUnixTime, hostname, numToSI } from "@utils/helpers";
|
||||||
import { isImage, isVideo } from "@utils/media";
|
import { isImage, isVideo } from "@utils/media";
|
||||||
import {
|
import {
|
||||||
|
@ -38,7 +39,6 @@ import {
|
||||||
TransferCommunity,
|
TransferCommunity,
|
||||||
} from "lemmy-js-client";
|
} from "lemmy-js-client";
|
||||||
import { relTags } from "../../config";
|
import { relTags } from "../../config";
|
||||||
import { getExternalHost, getHttpBase } from "../../env";
|
|
||||||
import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
|
import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
|
||||||
import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
|
import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown";
|
||||||
import { I18NextService, UserService } from "../../services";
|
import { I18NextService, UserService } from "../../services";
|
||||||
|
|
|
@ -24,3 +24,5 @@ export const updateUnreadCountsInterval = 30000;
|
||||||
export const fetchLimit = 40;
|
export const fetchLimit = 40;
|
||||||
export const relTags = "noopener nofollow";
|
export const relTags = "noopener nofollow";
|
||||||
export const emDash = "\u2014";
|
export const emDash = "\u2014";
|
||||||
|
|
||||||
|
export const testHost = "0.0.0.0:8536";
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
import { isBrowser } from "@utils/browser";
|
|
||||||
|
|
||||||
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 getBaseLocal(s = "") {
|
|
||||||
return `http${s}://${getHost()}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getHttpBaseInternal() {
|
|
||||||
return getBaseLocal(); // Don't use secure here
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getHttpBaseExternal() {
|
|
||||||
return `http${getSecure()}://${getExternalHost()}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getHttpBase() {
|
|
||||||
return getBaseLocal(getSecure());
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isHttps() {
|
|
||||||
return getSecure() === "s";
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`httpbase: ${getHttpBase()}`);
|
|
||||||
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}`;
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
import { getHttpBase } from "@utils/env";
|
||||||
import { LemmyHttp } from "lemmy-js-client";
|
import { LemmyHttp } from "lemmy-js-client";
|
||||||
import { getHttpBase } from "../../shared/env";
|
|
||||||
import { toast } from "../../shared/toast";
|
import { toast } from "../../shared/toast";
|
||||||
import { I18NextService } from "./I18NextService";
|
import { I18NextService } from "./I18NextService";
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
// import Cookies from 'js-cookie';
|
// import Cookies from 'js-cookie';
|
||||||
import { isAuthPath } from "@utils/app";
|
import { isAuthPath } from "@utils/app";
|
||||||
import { isBrowser } from "@utils/browser";
|
import { isBrowser } from "@utils/browser";
|
||||||
|
import { isHttps } from "@utils/env";
|
||||||
import IsomorphicCookie from "isomorphic-cookie";
|
import IsomorphicCookie from "isomorphic-cookie";
|
||||||
import jwt_decode from "jwt-decode";
|
import jwt_decode from "jwt-decode";
|
||||||
import { LoginResponse, MyUserInfo } from "lemmy-js-client";
|
import { LoginResponse, MyUserInfo } from "lemmy-js-client";
|
||||||
import { isHttps } from "../env";
|
|
||||||
import { toast } from "../toast";
|
import { toast } from "../toast";
|
||||||
import { I18NextService } from "./I18NextService";
|
import { I18NextService } from "./I18NextService";
|
||||||
|
|
||||||
|
|
5
src/shared/utils/env/get-base-local.ts
vendored
Normal file
5
src/shared/utils/env/get-base-local.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { getHost } from "@utils/env";
|
||||||
|
|
||||||
|
export default function getBaseLocal(s = "") {
|
||||||
|
return `http${s}://${getHost()}`;
|
||||||
|
}
|
14
src/shared/utils/env/get-external-host.ts
vendored
Normal file
14
src/shared/utils/env/get-external-host.ts
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { isBrowser } from "@utils/browser";
|
||||||
|
import { testHost } from "../../config";
|
||||||
|
|
||||||
|
export default 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;
|
||||||
|
}
|
6
src/shared/utils/env/get-host.ts
vendored
Normal file
6
src/shared/utils/env/get-host.ts
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { isBrowser } from "@utils/browser";
|
||||||
|
import { getExternalHost, getInternalHost } from "@utils/env";
|
||||||
|
|
||||||
|
export default function getHost() {
|
||||||
|
return isBrowser() ? getExternalHost() : getInternalHost();
|
||||||
|
}
|
5
src/shared/utils/env/get-http-base-external.ts
vendored
Normal file
5
src/shared/utils/env/get-http-base-external.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { getExternalHost, getSecure } from "@utils/env";
|
||||||
|
|
||||||
|
export default function getHttpBaseExternal() {
|
||||||
|
return `http${getSecure()}://${getExternalHost()}`;
|
||||||
|
}
|
5
src/shared/utils/env/get-http-base-internal.ts
vendored
Normal file
5
src/shared/utils/env/get-http-base-internal.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { getBaseLocal } from "@utils/env";
|
||||||
|
|
||||||
|
export default function getHttpBaseInternal() {
|
||||||
|
return getBaseLocal(); // Don't use secure here
|
||||||
|
}
|
5
src/shared/utils/env/get-http-base.ts
vendored
Normal file
5
src/shared/utils/env/get-http-base.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { getBaseLocal, getSecure } from "@utils/env";
|
||||||
|
|
||||||
|
export default function getHttpBase() {
|
||||||
|
return getBaseLocal(getSecure());
|
||||||
|
}
|
8
src/shared/utils/env/get-internal-host.ts
vendored
Normal file
8
src/shared/utils/env/get-internal-host.ts
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import { isBrowser } from "@utils/browser";
|
||||||
|
import { testHost } from "../../config";
|
||||||
|
|
||||||
|
export default function getInternalHost() {
|
||||||
|
return !isBrowser()
|
||||||
|
? process.env.LEMMY_UI_LEMMY_INTERNAL_HOST ?? testHost
|
||||||
|
: testHost; // used for local dev
|
||||||
|
}
|
11
src/shared/utils/env/get-secure.ts
vendored
Normal file
11
src/shared/utils/env/get-secure.ts
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { isBrowser } from "@utils/browser";
|
||||||
|
|
||||||
|
export default function getSecure() {
|
||||||
|
return (
|
||||||
|
isBrowser()
|
||||||
|
? window.location.protocol.includes("https")
|
||||||
|
: process.env.LEMMY_UI_HTTPS === "true"
|
||||||
|
)
|
||||||
|
? "s"
|
||||||
|
: "";
|
||||||
|
}
|
9
src/shared/utils/env/http-external-path.ts
vendored
Normal file
9
src/shared/utils/env/http-external-path.ts
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import { getExternalHost, getSecure } from "@utils/env";
|
||||||
|
|
||||||
|
// This is for html tags, don't include port
|
||||||
|
export default function httpExternalPath(path: string) {
|
||||||
|
return `http${getSecure()}://${getExternalHost().replace(
|
||||||
|
/:\d+/g,
|
||||||
|
""
|
||||||
|
)}${path}`;
|
||||||
|
}
|
23
src/shared/utils/env/index.ts
vendored
Normal file
23
src/shared/utils/env/index.ts
vendored
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import getBaseLocal from "./get-base-local";
|
||||||
|
import getExternalHost from "./get-external-host";
|
||||||
|
import getHost from "./get-host";
|
||||||
|
import getHttpBase from "./get-http-base";
|
||||||
|
import getHttpBaseExternal from "./get-http-base-external";
|
||||||
|
import getHttpBaseInternal from "./get-http-base-internal";
|
||||||
|
import getInternalHost from "./get-internal-host";
|
||||||
|
import getSecure from "./get-secure";
|
||||||
|
import httpExternalPath from "./http-external-path";
|
||||||
|
import isHttps from "./is-https";
|
||||||
|
|
||||||
|
export {
|
||||||
|
getBaseLocal,
|
||||||
|
getExternalHost,
|
||||||
|
getHost,
|
||||||
|
getHttpBase,
|
||||||
|
getHttpBaseExternal,
|
||||||
|
getHttpBaseInternal,
|
||||||
|
getInternalHost,
|
||||||
|
getSecure,
|
||||||
|
httpExternalPath,
|
||||||
|
isHttps,
|
||||||
|
};
|
5
src/shared/utils/env/is-https.ts
vendored
Normal file
5
src/shared/utils/env/is-https.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { getSecure } from "@utils/env";
|
||||||
|
|
||||||
|
export default function isHttps() {
|
||||||
|
return getSecure() === "s";
|
||||||
|
}
|
Loading…
Reference in a new issue