-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
75 lines (63 loc) · 2.3 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require('dotenv').config()
require('express-async-errors')
const express = require('express')
const app = express()
// rest of the packages
const morgan = require('morgan')
const cors = require('cors')
const helmet = require('helmet')
const xss = require('xss-clean')
const mongoSanitize = require('express-mongo-sanitize')
const cloudinary = require('cloudinary').v2
cloudinary.config({
cloud_name: process.env.CLOUD_NAME,
api_key: process.env.CLOUD_API_KEY,
api_secret: process.env.CLOUD_API_SECRET,
})
// database
const connectDB = require('./db/connect')
// routers
const authRouter = require('./routes/authRoutes')
const StudentRouter = require('./routes/studentRoutes')
const userRouter = require('./routes/userRoutes')
const topicRouter = require('./routes/topicRoutes')
const adminsubRoute = require('./routes/adminSubRoutes') //admin subtype routes
const adminmarkscheme = require('./routes/adminMarkSchemeRoutes') //admin marchscheme router
const evaluationRouter = require('./routes/evaluationRoutes')
const submissionRouter = require('./routes/submissionRoutes')
const panelRouter = require('./routes/panelRouter')
// middleware
const notFoundMiddleware = require('./middleware/not-found.js')
const errorHandlerMiddleware = require('./middleware/error-handler.js')
app.use(helmet()) // set security related http headers
app.use(cors()) // allow cross origin requests
app.use(xss()) // sanitize user inputs
app.use(mongoSanitize()) // protect against MongoDB injection
app.use(morgan('tiny'))
app.use(express.json())
app.get('/', (req, res) => {
res.send('<center><h1>Research Management Tool Backend</h1></center>')
})
app.use('/api/v1/auth', authRouter)
app.use('/api/v1/student', StudentRouter)
app.use('/api/v1/users', userRouter)
app.use('/api/v1/topic', topicRouter)
app.use('/api/v1/evaluate', evaluationRouter)
app.use('/api/v1/submission', submissionRouter)
app.use('/api/v1/subtype', adminsubRoute)
app.use('/api/v1/markscheme', adminmarkscheme)
app.use('/api/v1/panel', panelRouter)
app.use(notFoundMiddleware)
app.use(errorHandlerMiddleware)
const port = process.env.PORT || 5000
const start = async () => {
try {
await connectDB(process.env.MONGO_URL)
app.listen(port, () => {
console.log(`Server is listening on port ${port}...`)
})
} catch (error) {
console.log(error)
}
}
start()