-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (35 loc) · 1 KB
/
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
40
41
42
43
44
45
const express = require('express')
const mongoose = require('mongoose')
const bodyParser = require('body-parser')
const wallets = require('./routes/api/wallet')
const cors = require('cors')
const resolvePath = require('path').resolve
const app = express()
app.use(bodyParser.json())
app.use(cors())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(express.static(resolvePath(__dirname, './build')))
// app.use(cors({
// methods: ['GET','POST','DELETE','UPDATE','PUT','PATCH']
// }));
// DB Config
const db = require('./config/keys').mongoURI
// Connect to Mongo
mongoose
.connect(db)
.then(() => console.log('MongoDB Connected ..!'))
.catch((err) => {
console.log(err)
})
// Use Routes
app.use('/api', wallets)
app.get('/*', (req, res) => {
const contents = fs.readFileSync(
resolvePath(__dirname, './build/index.html'),
'utf8',
)
res.send(contents)
})
const port = process.env.PORT || 5000
app.listen(port, () => `Server running on port ${port} 🔥`)