From: abias Date: Sun, 14 May 2023 20:25:03 +0000 (-0400) Subject: Use node env instead of version for environment specific logic X-Git-Url: http://these/git/%22https:/lemmy.ml/u/Liwott/%7Biframely.url%7D?a=commitdiff_plain;h=025daaa582c94bc4114330c5bac8bc1d44d74424;p=lemmy-ui.git Use node env instead of version for environment specific logic --- diff --git a/Dockerfile b/Dockerfile index 3d6d621..0a23ea8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ WORKDIR /usr/src/app ENV npm_config_target_arch=x64 ENV npm_config_target_platform=linux ENV npm_config_target_libc=musl +ENV NODE_ENV=production # Cache deps COPY package.json yarn.lock ./ diff --git a/dev.dockerfile b/dev.dockerfile index 0e925c0..0faa3ad 100644 --- a/dev.dockerfile +++ b/dev.dockerfile @@ -6,6 +6,7 @@ WORKDIR /usr/src/app ENV npm_config_target_arch=x64 ENV npm_config_target_platform=linux ENV npm_config_target_libc=musl +ENV NODE_ENV=development # Cache deps COPY package.json yarn.lock ./ diff --git a/src/server/index.tsx b/src/server/index.tsx index dab5341..e406e6f 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -26,7 +26,8 @@ import { initializeSite, isAuthPath, } from "../shared/utils"; -import { VERSION } from "../shared/version"; + +const { NODE_ENV } = process.env as Record; const server = express(); const [hostname, port] = process.env["LEMMY_UI_HOST"] @@ -161,6 +162,7 @@ server.get("/*", async (req, res) => { } let routeData = await Promise.all(promises); + // let routeData = [{ error: "I am an error, hear me roar!" } as any]; // Redirect to the 404 if there's an API error if (routeData[0] && routeData[0].error) { @@ -173,7 +175,7 @@ server.get("/*", async (req, res) => { // Exact error should only be seen in a development environment. Users // in production will get a more generic message. - if (VERSION === "dev") { + if (NODE_ENV === "development") { errorPageData.error = error; } @@ -188,6 +190,8 @@ server.get("/*", async (req, res) => { } } + console.log(routeData); + const isoData: IsoData = { path, site_res: site, @@ -287,7 +291,7 @@ server.get("/*", async (req, res) => { } catch (err) { console.error(err); res.statusCode = 500; - return res.send(VERSION === "dev" ? err.message : "Server error"); + return res.send(NODE_ENV === "development" ? err.message : "Server error"); } }); diff --git a/src/shared/components/app/error-page.tsx b/src/shared/components/app/error-page.tsx index 3b1628b..5c08dd5 100644 --- a/src/shared/components/app/error-page.tsx +++ b/src/shared/components/app/error-page.tsx @@ -13,11 +13,11 @@ export class ErrorPage extends Component { const errorPageData = this.getErrorPageData(); return ( -
+

{errorPageData ? "Error!" : "Page Not Found"}

{errorPageData - ? "There was an error on the server. Try refreshing your browser of coming back at a later time" + ? 'There was an error on the server. Try refreshing your browser. If that doesn\'t work, come back at a later time. If the problem persists, consider opening an issue.' : "The page you are looking for does not exist"}

{!errorPageData && ( @@ -38,7 +38,9 @@ export class ErrorPage extends Component {
)} - {errorPageData?.error && {errorPageData.error.message}} + {errorPageData?.error && ( + {errorPageData.error} + )}
); } diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 627caa2..70faddf 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -107,7 +107,7 @@ export type ThemeColor = export interface ErrorPageData { type: "error"; - error?: Error; + error?: string; adminMatrixIds?: string[]; } diff --git a/src/shared/version.ts b/src/shared/version.ts index 149d272..c1dba35 100644 --- a/src/shared/version.ts +++ b/src/shared/version.ts @@ -1 +1 @@ -export const VERSION = "unknown version" as string; +export const VERSION = "unknown version";