server frontend files through express

This commit is contained in:
Bilal Catic
2019-05-23 19:33:37 +02:00
parent 01244c3118
commit 3203c63a64

View File

@@ -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}!`));