-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (42 loc) · 1.31 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
//npm packages
import express from 'express'
import dotenv from 'dotenv'
import helmet from 'helmet'
import cookieParser from 'cookie-parser'
import compression from 'compression'
import cors from 'cors'
import xss from 'xss-clean'
import mongoSanitize from 'express-mongo-sanitize'
import swaggerUi from 'swagger-ui-express'
//Custom Modules,Packages,Configs,Etc
import corsOption from './helpers/cors/corsOption.js'
import { initRoutes } from './routes/index.routes.js'
import notFound from './errors/notFound.js'
import swaggerDocument from './swagger-output.json' assert { type: 'json' }
import { errorHandler } from './middleware/errorHandler/errorHandler.js'
const envFile =
process.env.NODE_ENV === 'production' ? '.env.production' : '.env.development'
dotenv.config({
path: envFile,
})
const app = express()
app.use(express.json({ limit: '10kb' }))
app.use(express.urlencoded({ extended: true }))
app.use(cookieParser())
app.use(helmet())
app.use(compression())
app.use(xss())
app.use(
mongoSanitize({
replaceWith: '_',
}),
)
app.use(cors(corsOption))
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))
app.disable('x-powered"-by')
app.set('trust proxy', 1) // trust first proxy
initRoutes(app)
app.use(notFound)
app.use(errorHandler)
export const PORT = process.env.PORT || 5000
export default app