app.js
784 Bytes
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
let express = require('express')
let cookieParser = require('cookie-parser')
var cors = require('cors')
var corsConfig = require('./config/cors')
const indexRouter = require('./routes/index')
const authRouter = require('./routes/authRouter')
let app = express()
app.use(cors(corsConfig))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cookieParser())
app.use('/', indexRouter)
app.use('/', authRouter)
app.use(function(req, res) {
res.status(400)
res.json({
success: false,
message: 'error'
})
})
app.use(function(err, req, res) {
res.locals.message = err.message
res.locals.error = req.app.get('env') === 'development' ? err : {}
res.status(err.status || 500)
res.json({
success: false
})
})
module.exports = app