express.js 541 Bytes
Newer Older
Yoon, Daeki's avatar
Yoon, Daeki committed
1
2
3
4
5
6
7
8
9
10
11
12
import express from 'express'
import bodyParser from 'body-parser'
import userRoutes from './user/user.routes.js'

const app = express()

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

app.use('/', userRoutes)

app.use((err, req, res, next) => {
Yoon, Daeki's avatar
Yoon, Daeki committed
13
14
15
16
17
18
19
20
21
  if (err.name === 'UnauthorizedError') {
    res.status(401).json({
      error: err.name + ': ' + err.message
    })
  } else if (err) {
    res.status(400).json({
      error: err.name + ': ' + err.message
    })
    console.log(err)
Yoon, Daeki's avatar
Yoon, Daeki committed
22
23
24
25
  }
})

export default app