diff --git a/src/server/index.tsx b/src/server/index.tsx index cd4e39c..e1b36e2 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -1,4 +1,5 @@ import { setupDateFns } from "@utils/app"; +import { getStaticDir } from "@utils/env"; import express from "express"; import path from "path"; import process from "process"; @@ -19,10 +20,7 @@ const [hostname, port] = process.env["LEMMY_UI_HOST"] server.use(express.json()); server.use(express.urlencoded({ extended: false })); -server.use( - `/static/${process.env.COMMIT_HASH}`, - express.static(path.resolve("./dist")) -); +server.use(getStaticDir(), express.static(path.resolve("./dist"))); server.use(setCacheControl); if (!process.env["LEMMY_UI_DISABLE_CSP"] && !process.env["LEMMY_UI_DEBUG"]) { diff --git a/src/server/utils/create-ssr-html.tsx b/src/server/utils/create-ssr-html.tsx index 014d325..f6d46b0 100644 --- a/src/server/utils/create-ssr-html.tsx +++ b/src/server/utils/create-ssr-html.tsx @@ -1,3 +1,4 @@ +import { getStaticDir } from "@utils/env"; import { Helmet } from "inferno-helmet"; import { renderToString } from "inferno-server"; import serialize from "serialize-javascript"; @@ -87,9 +88,7 @@ export async function createSsrHtml( - + ${helmet.link.toString() || fallbackTheme} @@ -104,9 +103,7 @@ export async function createSsrHtml(
${root}
- + `; diff --git a/src/shared/components/common/icon.tsx b/src/shared/components/common/icon.tsx index 4102e7b..92a41a3 100644 --- a/src/shared/components/common/icon.tsx +++ b/src/shared/components/common/icon.tsx @@ -1,3 +1,4 @@ +import { getStaticDir } from "@utils/env"; import classNames from "classnames"; import { Component } from "inferno"; import { I18NextService } from "../../services"; @@ -23,7 +24,9 @@ export class Icon extends Component { })} >
{this.props.icon} diff --git a/src/shared/components/person/person-listing.tsx b/src/shared/components/person/person-listing.tsx index 1d88e38..dfc5d66 100644 --- a/src/shared/components/person/person-listing.tsx +++ b/src/shared/components/person/person-listing.tsx @@ -1,4 +1,5 @@ import { showAvatars } from "@utils/app"; +import { getStaticDir } from "@utils/env"; import { hostname, isCakeDay } from "@utils/helpers"; import classNames from "classnames"; import { Component } from "inferno"; @@ -88,10 +89,7 @@ export class PersonListing extends Component { !this.props.person.banned && showAvatars() && ( )} diff --git a/src/shared/config.ts b/src/shared/config.ts index 3687e60..58ecc08 100644 --- a/src/shared/config.ts +++ b/src/shared/config.ts @@ -1,5 +1,7 @@ -export const favIconUrl = `/static/${process.env.COMMIT_HASH}/assets/icons/favicon.svg`; -export const favIconPngUrl = `/static/${process.env.COMMIT_HASH}/assets/icons/apple-touch-icon.png`; +import { getStaticDir } from "@utils/env"; + +export const favIconUrl = `${getStaticDir()}/assets/icons/favicon.svg`; +export const favIconPngUrl = `${getStaticDir()}/assets/icons/apple-touch-icon.png`; export const repoUrl = "https://github.com/LemmyNet"; export const joinLemmyUrl = "https://join-lemmy.org"; diff --git a/src/shared/utils/env/get-static-dir.ts b/src/shared/utils/env/get-static-dir.ts new file mode 100644 index 0000000..1d19596 --- /dev/null +++ b/src/shared/utils/env/get-static-dir.ts @@ -0,0 +1,5 @@ +// Returns path to static directory, intended +// for cache-busting based on latest commit hash. +export default function getStaticDir() { + return `/static/${process.env.COMMIT_HASH}`; +} diff --git a/src/shared/utils/env/index.ts b/src/shared/utils/env/index.ts index e14c673..3a9a3fe 100644 --- a/src/shared/utils/env/index.ts +++ b/src/shared/utils/env/index.ts @@ -6,6 +6,7 @@ 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 getStaticDir from "./get-static-dir"; import httpExternalPath from "./http-external-path"; import isHttps from "./is-https"; @@ -18,6 +19,7 @@ export { getHttpBaseInternal, getInternalHost, getSecure, + getStaticDir, httpExternalPath, isHttps, };