-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (29 loc) · 1.03 KB
/
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
30
31
32
33
34
35
36
37
38
const express = require('express')
const bodyParser = require('body-parser')
const cfenv = require('cfenv')
const userApi = require('./server/api/user.js')
const dbConn = require('./server/database/mongo-connect.js')
const client = require('./client/routes/route.js')
const validator = require('express-validator')
const app = express()
const env = cfenv.getAppEnv()
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(validator())
dbConn(env)
const apiPrefix = '/api'
const userRouter = express.Router()
userRouter.get('/', userApi.getUsers)
userRouter.get('/:id', userApi.getUser)
userRouter.post('/', userApi.createUser)
userRouter.delete('/:id', userApi.deleteUser)
userRouter.delete('/clean', userApi.cleanUsers)
app.use(`${apiPrefix}/user`, userRouter)
app.use(express.static(`${__dirname}/client/public/webapp`))
// bootstrap front-end app
client(app)
app.listen(env.port, () => {
if (env.isLocal === true) {
console.log(`Listening at ${env.url}`)
}
})