-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (29 loc) · 902 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
35
// Main starting point of App:
const express = require('express')
const bodyParser = require('body-parser')
const morgan = require('morgan')
const cors = require('cors')
const mongoose = require('mongoose')
const router = require('./router')
const keys = require('./config/keys');
// DB Setup:
// mongoose.Promise = global.Promise;
mongoose.connect(keys.mongoURI);
const app = express();
// App Setup:
app.use(morgan('combined'))
app.use(cors())
app.use(bodyParser.json())
router(app)
if (process.env.NODE_ENV === 'production'){
// Express will serve up production assets
app.use(express.static('client/build'));
// Express will serve up the index.html
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
});
}
// SERVER SETUP:
const PORT = process.env.PORT || 4000
app.listen(PORT);