-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
61 lines (52 loc) · 1.32 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
/**
* @author Ysn4Irix
* @email [email protected]
* @create date 09-09-2022
* @modify date 28-09-2022
*/
require('dotenv').config()
const express = require('express')
const morgan = require('morgan')
const helmet = require('helmet')
const cors = require('cors')
const responseTime = require('response-time')
const rateLimit = require('./middlewares/limiter')
const logger = require('./helpers/logger')
const app = express()
if (process.env.NODE_ENV === 'development') app.use(morgan('dev'))
app.set('trust proxy', 1)
app.use(responseTime())
app.use(helmet())
app.use(cors())
app.use(express.json())
app.use(
express.urlencoded({
extended: false
})
)
app.use(rateLimit)
app.use('/api', require('./routes/madina.route'))
app.use(require('./middlewares/notFoundHandler'))
const port = process.env.PORT
const server = app.listen(port, () => {
logger.info(
`🚀 Server started => listening on PORT: ${port} with processId: ${process.pid}`
)
})
process.on('SIGINT', () => {
logger.info('SIGINT signal received.')
logger.info('Server is closing.')
server.close(() => {
logger.info('Server closed.')
process.exit(0)
})
})
process.on('SIGTERM', () => {
logger.info('SIGTERM signal received.')
logger.info('Server is closed.')
server.close(() => {
logger.info('Server closed.')
process.exit(0)
})
})
module.exports = app