app.js 784 Bytes
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