From 317dd7b4d61fecb56e8744b95700c0242da9bf12 Mon Sep 17 00:00:00 2001
From: Lucendio <dev@lucend.io>
Date: Thu, 14 May 2020 01:21:55 +0200
Subject: [PATCH] Allow to overwrite location of the client build folder

* keep both in gitignore, since the default still exist
---
 app/.gitignore             |  1 +
 app/client/config/paths.js | 11 ++++++++++-
 app/server/src/index.js    |  2 +-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/app/.gitignore b/app/.gitignore
index 4e90b9c..cd02c38 100644
--- a/app/.gitignore
+++ b/app/.gitignore
@@ -1,3 +1,4 @@
 node_modules
 
 client/build
+server/src/public
diff --git a/app/client/config/paths.js b/app/client/config/paths.js
index b3fd764..1861110 100644
--- a/app/client/config/paths.js
+++ b/app/client/config/paths.js
@@ -21,6 +21,15 @@ const publicUrlOrPath = getPublicUrlOrPath(
   process.env.PUBLIC_URL
 );
 
+// NOTE: env var supersedes default
+//
+const defaultBuildPath = resolveApp('./build');
+const { BUILD_PATH = defaultBuildPath } = process.env;
+if( BUILD_PATH.length <= 0 ){
+    process.error( new Error(`environment variable 'BUILD_PATH' is defined but empty`) );
+}
+const buildPath = path.resolve( BUILD_PATH );
+
 const moduleFileExtensions = [
   'web.mjs',
   'mjs',
@@ -52,7 +61,7 @@ const resolveModule = (resolveFn, filePath) => {
 module.exports = {
   dotenv: resolveApp('.env'),
   appPath: resolveApp('.'),
-  appBuild: resolveApp('build'),
+  appBuild: buildPath,
   appPublic: resolveApp('public'),
   appHtml: resolveApp('public/index.html'),
   appIndexJs: resolveModule(resolveApp, 'src/index'),
diff --git a/app/server/src/index.js b/app/server/src/index.js
index 10c7256..ae64c5f 100644
--- a/app/server/src/index.js
+++ b/app/server/src/index.js
@@ -33,7 +33,7 @@ app.use(helmet.contentSecurityPolicy({
 
 app.use(todoRoutes);
 app.use(userRoutes);
-app.use('/', express.static(path.join(__dirname,`./../../client/build`)));
+app.use('/', express.static(path.resolve(__dirname, `./public`)));
 app.use(errorRoutes);
 
 
-- 
GitLab