express.js 765 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
import courseRoutes from './course/course.routes.js'
Yoon, Daeki's avatar
Yoon, Daeki committed
7
8
9
10
11
12

const app = express()

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

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

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

export default app