-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (40 loc) · 1.32 KB
/
index.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
46
47
48
49
require('dotenv').config()
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const cors = require('cors')
const path = require('path')
const { userController } = require('./controllers')
const { PORT } = process.env
app.use(express.static(path.join(__dirname, 'build')))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cors())
app.use('/api/user', require('./routes/user.route'))
app.use('/api/price', require('./routes/r-Price'))
app.use('/api/rooms', require('./routes/r-Room'))
app.use('/api/contracts', require('./routes/r-Contract'))
app.use('/api', require('./routes/redis.route'))
// For navigate app pages
app.get('/registration/verify/:userId?', userController.completeVerify)
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/build/index.html'))
})
// Not found route handler
app.use((req, res, next) => {
let err = new Error('Route not found!')
err.status = 404
return next(err)
})
// All the error will be turned into JSON in here
app.use((err, req, res, next) => {
return res.status(err.status).json({
errors: {
display: err.logicError,
debug: err.message,
occurAt: err.occurAt
},
})
})
app.listen(PORT, () => console.log(`[ SERVER IS STARTED ON PORT ${PORT} ]`))
module.exports = app