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

const app = express()

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

Yoon, Daeki's avatar
quiz    
Yoon, Daeki committed
12
app.use('/', authRoutes)
Yoon, Daeki's avatar
Yoon, Daeki committed
13
app.use('/', userRoutes)
Yoon, Daeki's avatar
quiz    
Yoon, Daeki committed
14
app.use('/', quizRoutes)
Yoon, Daeki's avatar
Yoon, Daeki committed
15
16

app.use((err, req, res, next) => {
Yoon, Daeki's avatar
Yoon, Daeki committed
17
18
19
20
21
22
23
24
25
  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
26
27
28
29
  }
})

export default app