server frontend files through express
This commit is contained in:
20
server.js
20
server.js
@@ -2,9 +2,29 @@
|
|||||||
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const routes = require('./routes');
|
const routes = require('./routes');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.PORT || 5000;
|
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.use('/api', routes);
|
||||||
app.listen(port, () => console.log(`App running on port ${port}!`));
|
app.listen(port, () => console.log(`App running on port ${port}!`));
|
||||||
|
|||||||
Reference in New Issue
Block a user