From: abias Date: Mon, 15 May 2023 03:45:21 +0000 (-0400) Subject: Fix things not working in production build X-Git-Url: http://these/git/%7B%24%7B%60data:application/%22%7Burl%7D/readmes/static/%7BrepoUrl%7D?a=commitdiff_plain;h=dbee2533a295efd63761ac7bc5767f482546254f;p=lemmy-ui.git Fix things not working in production build --- diff --git a/Dockerfile b/Dockerfile index 0a23ea8..3d6d621 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,6 @@ 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 0faa3ad..0e925c0 100644 --- a/dev.dockerfile +++ b/dev.dockerfile @@ -6,7 +6,6 @@ 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/package.json b/package.json index 332b888..0315416 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "isomorphic-cookie": "^1.2.4", "jwt-decode": "^3.1.2", "lemmy-js-client": "0.17.2-rc.15", + "lodash": "^4.17.21", "markdown-it": "^13.0.1", "markdown-it-container": "^3.0.0", "markdown-it-emoji": "^2.0.2", @@ -77,6 +78,7 @@ "sass": "^1.62.1", "sass-loader": "^13.2.2", "serialize-javascript": "^6.0.1", + "service-worker-webpack": "^1.0.0", "sharp": "^0.32.1", "tippy.js": "^6.3.7", "toastify-js": "^1.12.0", @@ -111,7 +113,6 @@ "prettier-plugin-organize-imports": "^3.2.2", "prettier-plugin-packagejson": "^2.4.3", "rimraf": "^5.0.0", - "service-worker-webpack": "^1.0.0", "sortpack": "^2.3.4", "style-loader": "^3.3.2", "terser": "^5.17.3", diff --git a/src/server/index.tsx b/src/server/index.tsx index 5e9b319..952bbde 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -27,8 +27,6 @@ import { isAuthPath, } from "../shared/utils"; -const { NODE_ENV } = process.env as Record; - const server = express(); const [hostname, port] = process.env["LEMMY_UI_HOST"] ? process.env["LEMMY_UI_HOST"].split(":") @@ -184,7 +182,7 @@ server.get("/*", async (req, res) => { const isoData: IsoDataOptionalSite = { path, site_res: site, - routeData, + routeData: getErrorRouteData("lel", site), }; const wrapper = ( @@ -200,7 +198,9 @@ server.get("/*", async (req, res) => { // If an error is caught here, the error page couldn't even be rendered console.error(err); res.statusCode = 500; - return res.send(NODE_ENV === "development" ? err.message : "Server error"); + return res.send( + process.env.NODE_ENV === "development" ? err.message : "Server error" + ); } }); @@ -295,9 +295,11 @@ async function fetchIconPng(iconUrl: string) { function getErrorRouteData(error: string, site?: GetSiteResponse) { const errorPageData: ErrorPageData = { type: "error" }; + console.log(`Error: ${process.env.NODE_ENV}`); + // Exact error should only be seen in a development environment. Users // in production will get a more generic message. - if (NODE_ENV === "development") { + if (process.env.NODE_ENV === "development") { errorPageData.error = error; } diff --git a/yarn.lock b/yarn.lock index 62da0d1..8291f28 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5546,7 +5546,7 @@ lodash@^3.10.1: resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" integrity sha512-9mDDwqVIma6OZX79ZlDACZl8sBm0TEnkf99zV3iMA4GzkIT/9hiqP5mY0HoT1iNLCrKc/R1HByV+yJfRWVJryQ== -lodash@^4.17.20: +lodash@^4.17.20, lodash@^4.17.21: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==