-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (24 loc) · 885 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, './.env') });
const express = require('express');
const backendRoutes = require('./routes/backendRoutes');
//const connectMDB = require('./config/db_client')
//connectMDB();
const app = express();
// move json data from and to react client
app.use(express.json());
app.use('/api/backend', backendRoutes);
// Server static assets if in production
if(process.env.NODE_ENV === 'production'){
//Set static folder
app.use(express.static(path.resolve(__dirname,'./frontend/build')));
app.get('*', (req,res) => {
res.sendFile(path.resolve(__dirname,'./frontend/build/index.html'))
});
}else{
app.get("/", (req, res) => {
res.json({ message: "API running..." });
});
}
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => console.log(`Server runnig on port ${PORT}`))