-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (27 loc) · 927 Bytes
/
index.js
File metadata and controls
31 lines (27 loc) · 927 Bytes
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 express from 'express'
import cors from 'cors'
import compression from 'compression'
import morgan from 'morgan'
import cacheController from 'express-cache-controller'
import bodyParser from 'body-parser'
import { errorHandler as queryErrorHandler } from 'querymen'
import { errorHandler as bodyErrorHandler } from 'bodymen'
import { cache } from '../../middlewares'
import { environment } from '../../config'
export default (apiRoot, routes) => {
const app = express()
/* istanbul ignore next */
if (environment === 'production' || environment === 'development') {
app.use(cors())
app.use(compression())
app.use(morgan('dev'))
}
app.use(cacheController({ public: true, maxAge: 300 }))
app.use(cache(300))
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(apiRoot, routes)
app.use(queryErrorHandler())
app.use(bodyErrorHandler())
return app
}