-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
42 lines (32 loc) · 1.1 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
const express = require('express')
const config = require('config')
const bodyParser = require('body-parser')
const path = require('path')
const yaml = require('js-yaml')
const fs = require('fs')
const swaggerUi = require('swagger-ui-express')
const morgan = require('morgan')
const logger = require('./helpers/logger')
const helmet = require('helmet')
// body parse
const app = express()
// helmet
app.use(helmet())
app.use(helmet.hidePoweredBy())
app.use(morgan('short', { stream: logger.stream }))
const server = require('http').Server(app)
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
const docs = yaml.safeLoad(fs.readFileSync('./docs/swagger.yml', 'utf8'))
app.use('/apidocs', swaggerUi.serve, swaggerUi.setup(docs))
// apis
app.use(require('./apis'))
// error handler
app.use(require('./middlewares/error'))
// start server
server.listen(config.get('server.port'), config.get('server.host'), function () {
const host = server.address().address
const port = server.address().port
console.info('Server start at http://%s:%s', host, port)
})
module.exports = app