-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (47 loc) · 1.35 KB
/
index.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
import express from 'express'
import env from 'dotenv'
// IMPORT DB CONNECTION
import mongodbConnection from './config/db.js'
// IMPORT ALL MIDDILEARES
import morgan from 'morgan'
import cors from 'cors'
import helmet from 'helmet'
import ExpressMongoSanitize from 'express-mongo-sanitize'
// IMPORTS ALL CUSTOM MIDDLEWARES
import { notFound, errorHandler } from './middlewares/errorMiddleware.js'
//IMPORT ALL ROUTES
import homeRoute from './routes/home.route.js'
import PublicRouter from './routes/public/index.js'
import PrivateRouter from './routes/private/index.js'
const app = express()
env.config()
// set security HTTP headers
app.use(helmet())
app.disable('x-powered-by')
// parse urlencoded request body
app.use(express.urlencoded({ limit: '69mb' }))
app.use(express.urlencoded({ extended: true }))
// parse json request body
app.use(express.json())
app.use(ExpressMongoSanitize())
// enable cors
app.use(cors())
app.options('*', cors())
// Mongodb connection
mongodbConnection()
// Middleware
app.use(morgan('dev'))
// HOME ROUTE
app.use('/', homeRoute)
// PUBLIC ROUTE
app.use('/public', PublicRouter)
// PRIVATE ROUTE
app.use('/private', PrivateRouter)
// custom middleware
app.use(notFound)
app.use(errorHandler)
// Server Listen
const PORT = process.env.PORT || 5000
app.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`)
})