-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
29 lines (24 loc) · 927 Bytes
/
server.js
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
const express = require('express')
const app = express()
const mongoose = require('mongoose')
const morgan = require('morgan')
require('dotenv').config()
const { expressjwt } = require('express-jwt')
app.use(express.json())
app.use(morgan('dev'))
mongoose.set('strictQuery', false);
mongoose.connect(process.env.MONGO_URI, (err) => {
console.log('Connected to DB', err)
})
app.use('/api/auth', require('./routes/authRouter'))
app.use('/api/main', expressjwt({secret: process.env.SECRET, algorithms: ['HS256']}))
app.use('/api/main/issue', require('./routes/issueRouter'))
app.use('/api/main/comments', require('./routes/commentRouter'))
app.use((err, req, res, next) => {
console.log(err)
if (err.name === "UnauthorizedError") {
res.status(err.status)
}
return res.send({ errMsg: err.message })
})
app.listen(process.env.PORT, () => console.log(`Server is running on port ${process.env.PORT}`))