From 856e95a021789b91183555dab60cbaf9b3dc274d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 8 Aug 2019 12:37:51 -0400 Subject: [PATCH] add a catch-all to express for paths not matching specific files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For more details see this issue: https://stackoverflow.com/questions/27928372/react-router-urls-dont-work-when-refreshing-or-writing-manually Signed-off-by: Jakub SokoĊ‚owski --- back-end/server.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/back-end/server.js b/back-end/server.js index 52a5195..1c7bfec 100644 --- a/back-end/server.js +++ b/back-end/server.js @@ -1,3 +1,4 @@ +const path = require('path') const config = require('./config') function setupSystem() { @@ -23,6 +24,12 @@ async function setupAPI() { setupPostRoutedAppMiddlewares(app); app.use(express.static('frontend')); + + /* Handles any requests that don't match the ones above */ + app.get('*', (req,res) =>{ + res.sendFile(path.join(__dirname, 'frontend/index.html')); + }); + app.listen(config.PORT); console.log(`Server started on port: ${config.PORT}`);