-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
39 lines (33 loc) · 917 Bytes
/
server.ts
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
import * as express from 'express'
import * as mongoose from 'mongoose'
import * as bodyParser from 'body-parser'
import * as cookieParser from 'cookie-parser'
import * as logger from 'morgan'
import * as helmet from 'helmet'
import * as cors from 'cors'
import config from './config/main'
import router from './router/v1'
// init express
const app = express()
// init mongoose
mongoose.connect(config.db)
// express middleware
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(cookieParser())
app.use(logger('dev'))
app.use(helmet())
app.use(cors())
// router
router(app)
// init server
let server
if (process.env.NODE_ENV !== config.test_env) {
server = app.listen(config.port)
console.log(`Server listening on ${config.port}`)
} else {
server = app.listen(config.test_port)
console.log(`Server listening on ${config.test_port}`)
}
// export
export default server