-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (29 loc) · 1008 Bytes
/
server.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
36
37
38
39
const express = require('express')
const app = express()
const mongoose = require('mongoose')
const { PORT, mongoUri } = require('./config')
const cors = require('cors')
const morgan = require('morgan')
const activitiesRoutes = require('./routes/api/endpoints')
const path = require('path')
app.use(cors())
app.use(morgan('tiny'))
app.use(express.json());
app.use(express.urlencoded({extended: true}));
mongoose
.connect(mongoUri, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
.then(() => console.log('MongoDB database Connected...'))
.catch((err) => console.log(err))
app.use('/api/', activitiesRoutes)
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/dist'))
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'dist', 'index.html'))
})
}
app.listen(PORT, () => console.log(`App listening at http://localhost:${PORT}`))