-
Notifications
You must be signed in to change notification settings - Fork 84
/
server.js
39 lines (33 loc) · 1.09 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
var express = require('express')
var path = require('path')
var bodyParser = require('body-parser')
var mongo = require('mongoose')
const { mongoURI } = require('./config/keys')
const { connectToDb } = require('./db/connection')
const { handleUserGet, handleUserDelete, handleUserSave } = require('./controllers/User')
connectToDb(mongo, mongoURI)
.then((res) => {
console.log('Database connection details:-')
console.log(JSON.stringify(res, undefined, 2))
})
.catch((err) => { console.log(err.message) })
var app = express()
app.use(bodyParser())
app.use(bodyParser.json({
limit: '5mb'
}))
app.use(bodyParser.urlencoded({
extended: true
}))
var distDir = __dirname + '/dist/'
app.use(express.static(distDir))
const { Model } = require('./db/models/User')
app.post('/api/SaveUser', handleUserSave(Model))
app.post('/api/deleteUser', handleUserDelete(Model))
app.get('/api/getUser', handleUserGet(Model))
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/dist/index.html'))
})
app.listen(process.env.PORT || 8080, () => {
console.log('App listening on port 8080!\n')
})