-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
29 lines (22 loc) · 882 Bytes
/
app.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
const express = require('express')
const mongoose = require('mongoose')
const config = require('config')
const app = express()
module.exports = app
app.use(express.json())
app.use(express.urlencoded({ extended: false }));
const db = config.get('mongoURI')
mongoose.
connect(db, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true })
.then(() => console.log('MongoDb connected...'))
.catch(err => console.log(err))
app.use('/api/books', require('./server/routes/api/books'))
const path = require('path')
// app.use('*', express.static(path.join(__dirname, 'client', 'index.html')))
// Serve react client static assets if in production
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'))
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
})
}