-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (28 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
const express = require('express');
const mongoose = require('mongoose');
const app = express();
const keys = require('./config/keys');
const bodyParser = require('body-parser');
require('./routes/auth')(app);
require('./models/User');
const User = mongoose.model('users');
// app.get('/', (req, res) => {
// res.send({ hi: 'there there' });
// });
app.use(bodyParser.json());
mongoose.connect(keys.mongoURI, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
});
if (process.env.NODE_ENV === 'production') {
//Express should serve up production assests
app.use(express.static('client/build'));
//if no route is recognized, serve index.html file
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
// const PORT =
app.listen(process.env.PORT || 5000);