-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (45 loc) · 1.6 KB
/
app.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
const express = require('express')
const bodyParser = require('body-parser')
const appointmentRouter = require('./routes/appointment')
const rateLimiter = require('./ratelimiting/ratelimiter')
const helmet = require('helmet')
const auth0 = require('./auth/auth0')
// const cronMiddleware = require('./cronjob/cron-job')
const logger = require('./logger/logger')
const mongodbConnect = require('./db/mongodb')
const { requiresAuth } = require('express-openid-connect')
const config = require('./config/config')
require('dotenv').config()
const app = express()
// middlewares
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
app.use(auth0)
// app.use(cronMiddleware)
app.use('/api/v1/appointment', appointmentRouter)
// protected routes
app.use('/api/v1/appointment/create', requiresAuth(), appointmentRouter)
app.use('/api/v1/appointment/update/:id', requiresAuth(), appointmentRouter)
app.use('/api/v1/appointment/delete/:id', requiresAuth(), appointmentRouter)
app.use('/api/v1/appointment/userAppointment', requiresAuth(), appointmentRouter)
/// error handler middleware
app.use((err, req, res, next) => {
console.log(err.message)
res.status(500).send({
error: 'An unexpected error occurred'
})
next()
})
// security middleware
app.use(helmet())
// rate limiting middleware to all requests
app.use(rateLimiter)
// mongodb connection
mongodbConnect()
// full calendar initialization
app.get('/', requiresAuth(), (req, res) => {
res.send('appointment management API');
});
app.listen(config.PORT, () => {
console.log(`server is listening on port: ${config.PORT}...`);
})