-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
31 lines (26 loc) · 899 Bytes
/
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
import 'dotenv/config'
import express from 'express'
import bodyParser from 'body-parser'
import cors from 'cors'
import appConfig from './src/configs/app.config.js'
import { healthRoute, userRoute } from './src/routes/index.routes.js'
import logger from './src/configs/logger.config.js'
import db from './src/models/index.model.js'
import { errorHandler } from './src/middlewares/errorHandler.js'
const app = express()
const { HOSTNAME, PORT, ENVIRONMENT } = appConfig
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(cors())
app.use('/', healthRoute, userRoute)
// ERROR HANDLER MIDDLEWARE
app.use(errorHandler)
if (ENVIRONMENT === 'test' || ENVIRONMENT === 'dev') {
db.testConnection()
db.sequelize.sync()
}
app.listen(PORT, () => {
if (ENVIRONMENT !== 'prod')
logger.info(`Server running at http://${HOSTNAME}:${PORT}`)
})
export default app