From 7ae0df2cbcb8b5a21b75be629c7755f285684f54 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 21 Dec 2017 11:55:09 -0700 Subject: [PATCH] fixed dist loading error --- routes/index.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/routes/index.js b/routes/index.js index 510a6b403..506ed3cfb 100644 --- a/routes/index.js +++ b/routes/index.js @@ -25,19 +25,29 @@ const router = express.Router(); if (!DISABLE_STATIC_SERVER) { /** - * Serve the directories under public/dist from this router. + * Serve the directories under public. */ - router.use('/public', express.static(path.join(__dirname, '../public'))); - router.use('/static', staticMiddleware(path.resolve(path.join(__dirname, '../dist')), { - indexFromEmptyFile: false, - enableBrotli: true, - customCompressions: [ - { - encodingName: 'deflate', - fileExtension: 'zz', - }, - ], - })); + const public = path.resolve(path.join(__dirname, '../public')); + router.use('/public', express.static(public)); + + /** + * Serve the directories under dist. + */ + const dist = path.resolve(path.join(__dirname, '../dist')); + if (process.env.NODE_ENV === 'production') { + router.use('/static', staticMiddleware(dist, { + indexFromEmptyFile: false, + enableBrotli: true, + customCompressions: [ + { + encodingName: 'deflate', + fileExtension: 'zz', + }, + ], + })); + } else { + router.use('/static', express.static(dist)); + } } // Add the i18n middleware to all routes.