From: SleeplessOne1917 Date: Thu, 29 Jun 2023 20:33:08 +0000 (-0400) Subject: Fix dev caching issue X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/%7Bthis.props.imageSrc%7D?a=commitdiff_plain;h=2d88e42cabac606d2b7f201fcce6985f9da538f4;p=lemmy-ui.git Fix dev caching issue --- diff --git a/src/server/middleware.ts b/src/server/middleware.ts index 84c568d..f64b781 100644 --- a/src/server/middleware.ts +++ b/src/server/middleware.ts @@ -29,10 +29,13 @@ export function setCacheControl( ) { const user = UserService.Instance; let caching: string; + console.log("In middleware"); + console.log(process.env.NODE_ENV); if ( - req.path.match(/\.(js|css|txt|manifest\.webmanifest)\/?$/) || - req.path.includes("/css/themelist") + process.env.NODE_ENV === "production" && + (req.path.match(/\.(js|css|txt|manifest\.webmanifest)\/?$/) || + req.path.includes("/css/themelist")) ) { // Static content gets cached publicly for a day caching = "public, max-age=86400"; diff --git a/webpack.config.js b/webpack.config.js index 9afdb52..0c9806d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -14,7 +14,7 @@ const banner = ` @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 `; -function getBase(env) { +function getBase(env, mode) { return { output: { filename: "js/server.js", @@ -54,6 +54,7 @@ function getBase(env) { plugins: [ new webpack.DefinePlugin({ "process.env.COMMIT_HASH": `"${env.COMMIT_HASH}"`, + "process.env.NODE_ENV": `"${mode}"`, }), new MiniCssExtractPlugin({ filename: "styles/styles.css", @@ -69,7 +70,7 @@ function getBase(env) { } const createServerConfig = (env, mode) => { - const base = getBase(env); + const base = getBase(env, mode); const config = merge({}, base, { mode, entry: "./src/server/index.tsx", @@ -97,7 +98,7 @@ const createServerConfig = (env, mode) => { }; const createClientConfig = (env, mode) => { - const base = getBase(env); + const base = getBase(env, mode); const config = merge({}, base, { mode, entry: "./src/client/index.tsx",