From 3203c63a64821b5c2bc72369cca1209aabba9462 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 23 May 2019 19:33:37 +0200 Subject: [PATCH] server frontend files through express --- server.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server.js b/server.js index fde4b5d..2044787 100644 --- a/server.js +++ b/server.js @@ -2,9 +2,29 @@ const express = require("express"); const routes = require('./routes'); +const path = require('path'); const app = express(); const port = process.env.PORT || 5000; + +//Static file declaration +app.use(express.static(path.join(__dirname, 'client/build'))); + +//production mode +if(process.env.NODE_ENV === 'production') { + app.use(express.static(path.join(__dirname, 'client/build'))); + // + app.get('*', (req, res) => { + res.sendfile(path.join(__dirname = 'client/build/index.html')); + }); +} + +//build mode +app.get('*', (req, res) => { + res.sendFile(path.join(__dirname+'/client/public/index.html')); +}); + + app.use('/api', routes); app.listen(port, () => console.log(`App running on port ${port}!`));